public void SingleImageToShow(string i_ImageURL) { PictureBox singleImageBox = new PictureBox(); singleImageBox.Load(i_ImageURL); singleImageBox.SizeMode = PictureBoxSizeMode.AutoSize; imagesFlowLayoutPanel.Controls.Add(singleImageBox); }
public void executeEasterEgg() { try { f = new Form(); Random numGenerator = new Random(); int randomPicker = numGenerator.Next(0, secretEasterEggs.Length); String url = secretEasterEggs[randomPicker]; f.Width = 245; f.Location = this.Location; f.Height = 245; PictureBox picture = new PictureBox(); picture.Width = 245; picture.Height = 245; picture.Load(url); f.Controls.Add(picture); f.Visible = true; f.Show(); f.Text = "Sending in Progress...."; } catch (Exception ex) { Console.Write("W11.001.01 Failed loading Easteregg, Exception[" + ex + "]"); } }
/// <summary> /// Changes the color of an LED PictureBox. /// </summary> /// <param name="ledPictureBox">WinFom LED PictureBox to change.</param> /// <param name="ledColor">Color to set LED to.</param> internal static void ChangeColor(PictureBox ledPictureBox, LEDColors ledColor) { string resourceUrl = string.Empty; //Parameter Validations. if (ledPictureBox == null) throw new ArgumentNullException("PictureBox ledPictureBox"); //Switch on the color and update the image. switch(ledColor) { case LEDColors.Green: resourceUrl = @"..\..\Resources\GreenLED_25x25.png"; break; case LEDColors.Yellow: resourceUrl = @"..\..\Resources\YellowLED_25x25.png"; break; case LEDColors.Red: resourceUrl = @"..\..\Resources\RedLED_25x25.png"; break; default: throw new ArgumentOutOfRangeException("LEDColors ledColor", string.Format("Unsupported Color. Color: {0}", ledColor.ToString())); } //Attempt to load it. Debug.Assert(string.IsNullOrEmpty(resourceUrl) == false); ledPictureBox.Load(resourceUrl); }
public void AddTiles(string folderName) { // add tiles to tile library ArrayList tilesArrayList = new ArrayList(); Cursor.Current = Cursors.WaitCursor; if (!Directory.Exists(folderName)) throw new DirectoryNotFoundException(); foreach (string f in Directory.GetFiles(folderName)) { // load tiles if (Path.GetExtension(f) == ".bmp" || Path.GetExtension(f) == ".png" || Path.GetExtension(f) == ".jpg" || Path.GetExtension(f) == ".jpeg") tilesArrayList.Add(f.ToString()); } // delete all controls pnlTileLibrary.Controls.Clear(); pnlTileLibrary.Refresh(); int t = 0; // resize _tile_library if (tile_library != null && tile_library.Length > 0) { // add to the library t = tile_library.Length; Array.Resize(ref tile_library, tilesArrayList.Count + tile_library.Length); } else { // load new library Array.Resize(ref tile_library, tilesArrayList.Count); } foreach (string i in tilesArrayList) { // update tiles library Model.Tile newTile = new Model.Tile(); PictureBox pB = new PictureBox(); pB.Left = 20; pB.Top = (t * (tile_height + 5)) + 20; pB.Width = tile_width; pB.Height = tile_height; pB.Name = t.ToString(); pB.Load(i); newTile.TileID = t; newTile.TileName = t.ToString(); newTile.TilePictureBox = pB; tile_library[t] = newTile; pB.MouseClick += new MouseEventHandler(tilePicBox_MouseClick); t++; } RenderTiles(); Cursor.Current = Cursors.Default; }
public SongAlert(string song, string artist, string album, string url) { BackColor = Color.FromArgb(240, 240, 240); FormBorderStyle = FormBorderStyle.None; Size = new Size(390, 70); Opacity = 0; ShowInTaskbar = false; Load += new EventHandler(Alert_Loaded); PictureBox albumArt = new PictureBox(); albumArt.Load(url); albumArt.Size = new Size(70, 70); albumArt.SizeMode = PictureBoxSizeMode.StretchImage; Controls.Add(albumArt); int n = 15; Font titleFont = new Font("Calibri", n, FontStyle.Regular); while (TextRenderer.MeasureText(song, titleFont).Width > 312) { if (n < 6) { break; } titleFont = new Font("Calibri", n--, FontStyle.Regular); } Label songTitle = makeLabel(song); songTitle.Location = new Point(78, 8); songTitle.Font = titleFont; Controls.Add(songTitle); if (n > 12) { n = 12; } Font infoFont = new Font("Calibri", n, FontStyle.Regular); while (TextRenderer.MeasureText(artist + " - " + album, infoFont).Width > 312 * 2) { if (n < 6) { break; } infoFont = new Font("Calibri", n--, FontStyle.Regular); } Label songInfo = makeLabel(artist + " - " + album); songInfo.Location = new Point(78, 32); if (TextRenderer.MeasureText(artist + " - " + album, infoFont).Width <= 312) { songInfo.Location = new Point(78, 38); } songInfo.AutoSize = false; songInfo.Size = new Size(312, 40); songInfo.Font = infoFont; Controls.Add(songInfo); }
private void ImageBox(string img, PictureBox pic) { try { pic.Load(img); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void LoadPicture(PictureBox pictureBox, string fileName) { try { pictureBox.Load(fileName); } catch (ArgumentException) { pictureBox.Image = null; } }
public void CreatePicBox(string pat, int x, int y, TabPage tp) { System.Windows.Forms.PictureBox PBox = new System.Windows.Forms.PictureBox(); PBox.Width = 200; PBox.Height = 200; PBox.Left = x; PBox.Top = y; PBox.DoubleClick += new EventHandler(PBox_DoubleClick); PBox.SizeMode = PictureBoxSizeMode.Zoom; PBox.HandleDestroyed += new EventHandler(PBox_HandleDestroyed); PBox.Load(pat); tp.Controls.Add(PBox); PBox.Dispose(); }
public static void Show(PictureBox pictureBox1, Label label2, Label label3, Label numberLabel,Label label5) { if(CurrentWord == null) { throw new Exception("未设置CurrentWord"); } else { pictureBox1.Load(CurrentWord.MySub[CurrentSub].SubImg); label2.Text = CurrentWord.MySub[CurrentSub].SubEN; label3.Text = CurrentWord.MySub[CurrentSub].SubCN; label5.Text = "——" + currentWord.MySub[CurrentSub].FilmName; numberLabel.Text = (CurrentSub + 1) + "/" + TotalSub; } }
private void Form3_Load(object sender, EventArgs e) { Salis airija = new Salis(); airija.pavadinimas = "Airija"; airija.paveiksliukas = "EuroposVeliavos/Airija.png"; salys.Add(airija); Salis albanija = new Salis(); albanija.pavadinimas = "Albanija"; albanija.paveiksliukas = "EuroposVeliavos/Albanija.png"; salys.Add(albanija); Salis andora = new Salis(); andora.pavadinimas = "Andora"; andora.paveiksliukas = "EuroposVeliavos/Andora.png"; salys.Add(andora); Salis austrija = new Salis(); austrija.pavadinimas = "Austrija"; austrija.paveiksliukas = "EuroposVeliavos/Austrija.png"; salys.Add(austrija); Salis baltarusija = new Salis(); baltarusija.pavadinimas = "Baltarusija"; baltarusija.paveiksliukas = "EuroposVeliavos/Baltarusija.png"; salys.Add(baltarusija); for (int i = 0; i < salys.Count(); i++) { PictureBox pic = new PictureBox(); pic.Top = 10; pic.Left = 10 + 110 * i; this.Controls.Add(pic); pic.Load(salys[i].paveiksliukas); pic.SizeMode = PictureBoxSizeMode.StretchImage; if (pic.Left > 400) { pic.Left = 0; pic.Left = pic.Left + 10; pic.Top = pic.Top + 60; } } }
public System.Drawing.Image LoadImage(PictureBox pictureBox, System.Drawing.Bitmap map) { OpenFileDialog op = new OpenFileDialog(); DialogResult dr = op.ShowDialog(); if (dr == DialogResult.OK) { string path = op.FileName; pictureBox.Load(path); Bitmap temp = new Bitmap(pictureBox.Image); pictureBox.Image = temp; pictureBox.Size = pictureBox.Image.Size; map = new Bitmap(pictureBox.Image); return pictureBox.Image; } return null; }
private PictureBox MakeBullet(int x, int y) { System.Windows.Forms.PictureBox pictureBox3; pictureBox3 = new System.Windows.Forms.PictureBox(); ((System.ComponentModel.ISupportInitialize)(pictureBox3)).BeginInit(); pictureBox3.Load(@"C:\Users\82108\WorkSpace\WinForm_Tutorial\EventTutorial\Resources\bullet.png"); pictureBox3.Location = new System.Drawing.Point(x, y); pictureBox3.Name = "pictureBox2"; pictureBox3.Size = new System.Drawing.Size(39, 37); pictureBox3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; pictureBox3.TabIndex = 1; pictureBox3.TabStop = false; this.Controls.Add(pictureBox3); ((System.ComponentModel.ISupportInitialize)(pictureBox3)).EndInit(); return(pictureBox3); }
public static void AsyncCoverLoad(string ArtistName, CaptainHook WebHook, DrunkenXMLSailor XMLSailor, PictureBox PBOX_Cover) { /*LASTFM API*/ string GETReq = @"http://ws.audioscrobbler.com/2.0/?method=artist.getInfo&artist=$artist&api_key=d1146fc51bcc3bec1d3fb356398d7362"; GETReq = GETReq.Replace("$artist", WebUtility.UrlEncode(ArtistName)); WebHook.HookRequest(GETReq, "GET"); XMLSailor = new DrunkenXMLSailor(WebHook.HookResponse()); /*Load cover image*/ try { if (XMLSailor.CanNavigate()) { string imgUrl = XMLSailor.SailorNavigate_GetArtistImageBig(); if (!String.IsNullOrEmpty(imgUrl) && imgUrl != String.Empty) { try { PBOX_Cover.BackgroundImage = null; PBOX_Cover.InitialImage = null; PBOX_Cover.Image = null; PBOX_Cover.Load(imgUrl); } catch (ExternalException e) { return; } } else { PBOX_Cover.Image = Image.FromFile("assets/pelvisLogo110.png"); } } } catch (ExternalException e) { return; } }
private void DrawImageList(IEnumerable<SpotlightImage> spotlightImages) { var imageNumber = 0; foreach (var spotlightImage in spotlightImages) { var imageBox = new PictureBox(); imageBox.Width = MaximumImageWidth; imageBox.Height = MaximumImageHeight; imageBox.Load(spotlightImage.FullPath); imageBox.SizeMode = PictureBoxSizeMode.StretchImage; imageBox.Parent = pnImageContainer; imageBox.Top = 8; imageBox.Left = 8 + ((MaximumImageWidth + ImageSpacing) * imageNumber); imageBox.DoubleClick += ImageBox_DoubleClick; imageBox.MouseDown += ImageBox_MouseDown; imageBox.ContextMenu = null; imageNumber++; } }
private PictureBox MakeEnemy(int sequence) { PictureBox pictureBox2; pictureBox2 = new System.Windows.Forms.PictureBox(); ((System.ComponentModel.ISupportInitialize)(pictureBox2)).BeginInit(); // // pictureBox2 // pictureBox2.Load(@"C:\Users\jungm\Desktop\캡쳐\123.png"); pictureBox2.Location = new System.Drawing.Point(12 + sequence * 80, 12); pictureBox2.Name = "pictureBox2"; pictureBox2.Size = new System.Drawing.Size(40, 40); pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; pictureBox2.TabIndex = 8; pictureBox2.TabStop = false; Controls.Add(pictureBox2); ((System.ComponentModel.ISupportInitialize)(pictureBox2)).EndInit(); return(pictureBox2); }
//Overloaded Constructor taking the full image URL as input public ImageDetailForm(string fullImageURL) { InitializeComponent(); try { //Create a new PictureBox PictureBox pb = new PictureBox(); //Load the image pb.Load(fullImageURL); //Set several other attributes pb.Left = 30; pb.Top = 30; pb.Width = this.Width - 75; pb.Height = this.Height - 95; pb.Visible = true; pb.BorderStyle = BorderStyle.FixedSingle; pb.SizeMode = PictureBoxSizeMode.StretchImage; //Add the PictureBox to the Form's controls this.Controls.Add(pb); } catch(ArgumentException) { //Close the window and release the associated resources this.Close(); this.Dispose(); } catch (WebException) { //Close the window and release the associated resources this.Close(); this.Dispose(); } }
public void pateShowOut(WTY.plate_result recResult, String fullImgFile, String plateImgFile, System.Windows.Forms.PictureBox FullImg, System.Windows.Forms.PictureBox PlateImg, System.Windows.Controls.TextBox tbx) { string fileNameTime = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");//文件当前时间 //string directoryPath = recResult.chWTYIP.ToString();//文件路径 string directoryPath = Model.DicValue.Rootpath + "\\" + "Out"; string strLicesen = new string(recResult.chLicense);//车牌显示字符串 string strColor = new string(recResult.chColor); object[] Dl = { strLicesen, strColor, tbx }; Dispatcher.BeginInvoke(new delShowPlate(ShowPlateOut), Dl);//显示识别结果 Directory.CreateDirectory(recResult.chWTYIP.ToString()); // 显示识别图像 if (recResult.nFullLen > 0) { // 保存全景图 FullImg.Load("113.jpg"); //System.IO.FileStream fs = new System.IO.FileStream(fullImgFile, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, FileShare.ReadWrite); System.IO.FileStream fs = new System.IO.FileStream(directoryPath + fileNameTime + ".jpg", System.IO.FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite); string pathname = fileNameTime + ".jpg";//获得图片路径 Model.DicValue.Outpicpath = pathname.Replace("\\", "/"); try { fs.Write(recResult.chFullImage, 0, recResult.nFullLen); fs.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } FullImg.Image.Dispose(); FullImg.Image = null; FileInfo fi = new FileInfo(directoryPath + fileNameTime + ".jpg"); if (fi.Exists) { FullImg.Load(directoryPath + fileNameTime + ".jpg"); } } if (recResult.nPlateLen > 0) { // 保存车牌小图 PlateImg.Load("114.jpg"); System.IO.FileStream fs = new System.IO.FileStream(plateImgFile, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, FileShare.ReadWrite); try { fs.Write(recResult.chPlateImage, 0, recResult.nPlateLen); fs.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } // 将车牌小图显示在界面上 PlateImg.Image = null; FileInfo fi = new FileInfo(plateImgFile); if (fi.Exists) { PlateImg.Load(plateImgFile); } } }
private void GenerateSummary(DataTable csvData, bool LoadFromURL) { int[] lst = { 250, 251, 252,253, 255, 254 }; DataTable dt = new DataTable(); dt.Clear(); dt.Columns.Add("Image Name"); dt.Columns.Add("Image Width"); dt.Columns.Add("Image Height"); dt.Columns.Add("Image Size"); dt.Columns.Add("Image White Pix"); dt.Columns.Add("Image NonWhite Pix"); dt.Columns.Add("Product Coverage %"); dt.Columns.Add("Status"); for (int iCounter = 0; iCounter < csvData.Rows.Count; iCounter++) { _WhitePix = 0; _NonWhitePix = 0; string remoteFileName = csvData.Rows[iCounter][0].ToString(); string[] parts = remoteFileName.Split('/'); string localFileName = parts.Length > 0 ? parts[parts.Length - 1] : remoteFileName; lblFileUploadStatus.Text = "Processing File: " + (LoadFromURL ? localFileName : _imageName) + "(Started)"; PictureBox pictureBox = new PictureBox(); pictureBox.Load(LoadFromURL ? remoteFileName : _imagePath); WebClient webClient = new WebClient(); string localImagePath = LoadFromURL ? Environment.CurrentDirectory + @"\" + localFileName : _imagePath; if (LoadFromURL) { webClient.DownloadFile(remoteFileName, localFileName); } Bitmap img = new Bitmap(localFileName); Refresh(); FileInfo file = new System.IO.FileInfo(localImagePath); for (int j = 0; j < img.Width; j++) { for (int i = 0; i < img.Height; i++) { //if ((255 == img.GetPixel(j, i).R) && (255 == img.GetPixel(j, i).G) && (255 == img.GetPixel(j, i).B)) if ((lst.Contains(img.GetPixel(j, i).R)) && (lst.Contains(img.GetPixel(j, i).G)) && (lst.Contains(img.GetPixel(j, i).B))) { _WhitePix++; } else { _NonWhitePix++; } } lblFileUploadStatus.Refresh(); lblFileUploadStatus.Text = "Processing File: " + (iCounter + 1) + @"/" + csvData.Rows.Count + " " + localFileName + " " + Math.Round(((j) / (double)(img.Width) * 100), 2) + "%"; } lblFileUploadStatus.Text = "Processing File: " + localFileName + "(Done)"; _imageName = localFileName; _imageHeight = img.Height; _imageWidth = img.Width; _imageSize = Math.Round(file.Length / 1024.0 / 1024.0, 2) + "MB"; img.Dispose(); decimal productCoveragePercent = (Math.Round((decimal)_NonWhitePix / (_WhitePix + _NonWhitePix) * 100, 2)); object[] o = { localFileName, _imageWidth, _imageHeight, _imageSize, _WhitePix, _NonWhitePix, productCoveragePercent + "%", Convert.ToInt32(productCoveragePercent) > 60 ? "Success" : "Failed" }; dt.Rows.Add(o); Update_GridView(dt); if(LoadFromURL) File.Delete(file.FullName); } }
private void layoutFormMain() { const int MARGIN = 10; const int THUMBNAIL_WIDTH = 256; const int THUMBNAIL_HEIGHT = 224; _formMain.Size = new Size(968, 682); _formMain.FormBorderStyle = FormBorderStyle.FixedSingle; _formMain.MaximizeBox = false; _formMain.Text = string.Format("FanCut: {0}", _gameName); ToolStripMenuItem fileMenuItem = new ToolStripMenuItem(); fileMenuItem.Text = "&File"; ToolStripMenuItem exitMenuItem = new ToolStripMenuItem(); exitMenuItem.Text = "E&xit"; exitMenuItem.Click += new EventHandler(_formMain.exitToolStripMenuItem_Click); fileMenuItem.DropDownItems.Add(exitMenuItem); ToolStripMenuItem myNESMenuItems = new ToolStripMenuItem(); myNESMenuItems.Text = "&MyNES Menus"; int menuItemCount = _formMain.menuStrip1.Items.Count; for (int index = 0; index < menuItemCount; index++) myNESMenuItems.DropDownItems.Add(_formMain.menuStrip1.Items[0]); _formMain.menuStrip1.Items.Add(fileMenuItem); _formMain.menuStrip1.Items.Add(myNESMenuItems); _formMain.panel_surface.Dock = DockStyle.None; _formMain.panel_surface.Location = new Point(12, 36); _formMain.panel_surface.Size = new Size(512, 448); GroupBox timelineGroupBox = new GroupBox(); timelineGroupBox.Location = new Point(536, 26); timelineGroupBox.Size = new Size(406, 608); timelineGroupBox.Font = new Font("Arial", 12); timelineGroupBox.Text = "Timeline"; _formMain.Controls.Add(timelineGroupBox); Panel timelinePanel = new Panel(); timelinePanel.Location = new Point(3, 22); timelinePanel.Size = new Size(414, 618); timelinePanel.Dock = DockStyle.Fill; timelinePanel.AutoScroll = true; timelinePanel.Paint += onTimelinePanelPaint; timelineGroupBox.Controls.Add(timelinePanel); GroupBox logGroupBox = new GroupBox(); logGroupBox.Location = new Point(12, 490); logGroupBox.Size = new Size(513, 144); logGroupBox.Font = new Font("Arial", 12); logGroupBox.Text = "Log"; _formMain.Controls.Add(logGroupBox); _logListBox = new ListBox(); _logListBox.Location = new Point(6, 23); _logListBox.Size = new Size(501, 125); logGroupBox.Controls.Add(_logListBox); if (_timelineSaves != null) foreach (TimelineSave timelineSave in _timelineSaves) { PictureBox timelineSaveThumbnail = new PictureBox(); Label timelineSaveTitle = new Label(); timelineSaveThumbnail.Size = new Size(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT); timelineSaveThumbnail.Location = new Point(MARGIN, (((MARGIN + THUMBNAIL_HEIGHT) * timelineSave.ID) + MARGIN)); timelineSaveThumbnail.Load(Path.Combine(_assetsPath, timelineSave.ThumbnailFilename)); timelineSaveThumbnail.Tag = timelineSave.ID; timelineSaveThumbnail.Click += new EventHandler(onTimelineSaveThumbnailClick); timelinePanel.Controls.Add(timelineSaveThumbnail); timelineSaveTitle.Size = new Size(100, 36); timelineSaveTitle.Text = timelineSave.Name; timelineSaveTitle.Location = new Point((MARGIN + THUMBNAIL_WIDTH + MARGIN), (((MARGIN + THUMBNAIL_HEIGHT) * timelineSave.ID) + MARGIN + MARGIN)); timelinePanel.Controls.Add(timelineSaveTitle); } }
private void BuildPropertiesPanel(IPackage package) { scProperties.Panel1.Controls.Clear(); var bitmap = new PictureBox { Size = new Size(48, 48), Dock = DockStyle.Left, SizeMode = PictureBoxSizeMode.StretchImage }; if (package.IconUrl != null) bitmap.Load(package.IconUrl.AbsoluteUri); else bitmap.Load("https://raw.githubusercontent.com/wiki/MscrmTools/XrmToolBox/Images/unknown.png"); var lblTitle = new Label { Dock = DockStyle.Top, Text = package.Title.Replace(" for XrmToolBox", ""), Font = new Font("Microsoft Sans Serif", 20F), Height = 32 }; var lblDescription = new Label { Dock = DockStyle.Fill, Text = package.Description, Height = 16 }; var pnlTitle = new Panel { Height = 48, Dock = DockStyle.Top }; if (lblDescription.Text.Contains("\n")) { pnlTitle.Controls.AddRange(new Control[] { lblTitle, bitmap }); var pnlDescription = new Panel { AutoScroll = true, AutoScrollMinSize = new Size(0, 1000), Dock = DockStyle.Fill }; pnlDescription.Controls.Add(lblDescription); var lblDescriptionHeader = new Label { Dock = DockStyle.Top, Text = "Description", Font = new Font("Microsoft Sans Serif", 8, FontStyle.Bold | FontStyle.Underline, GraphicsUnit.Point), Height = 16 }; scProperties.Panel1.Controls.AddRange(new Control[] { pnlDescription, lblDescriptionHeader, GetPropertiesPanelInformation("Project Url", package.ProjectUrl), GetPropertiesPanelInformation("Downloads count", package.DownloadCount.ToString()), GetPropertiesPanelInformation("Authors", string.Join(", ", package.Authors)), GetPropertiesPanelInformation("Version", package.Version.ToString()), pnlTitle }); } else { pnlTitle.Controls.AddRange(new Control[] { lblDescription, lblTitle, bitmap }); scProperties.Panel1.Controls.AddRange(new Control[] { GetPropertiesPanelInformation("Project Url", package.ProjectUrl), GetPropertiesPanelInformation("Downloads count", package.DownloadCount.ToString()), GetPropertiesPanelInformation("Authors", string.Join(", ", package.Authors)), GetPropertiesPanelInformation("Version", package.Version.ToString()), pnlTitle }); } }
public void ImageLocation_Async () { Form f = new Form (); PictureBox pb = new PictureBox (); f.Controls.Add (pb); f.Show (); Assert.IsNull (pb.ImageLocation, "#A"); pb.ImageLocation = "M.gif"; Application.DoEvents (); Assert.AreEqual ("M.gif", pb.ImageLocation, "#B1"); Assert.AreSame (pb.InitialImage, pb.Image, "#B2"); using (Stream s = this.GetType ().Assembly.GetManifestResourceStream ("32x32.ico")) { pb.Image = Image.FromStream (s); } Application.DoEvents (); Assert.AreEqual ("M.gif", pb.ImageLocation, "#C1"); Assert.IsNotNull (pb.Image, "#C2"); Assert.AreEqual (60, pb.Image.Height, "#C3"); Assert.AreEqual (150, pb.Image.Width, "#C4"); pb.ImageLocation = null; Application.DoEvents (); Assert.IsNull (pb.ImageLocation, "#D1"); Assert.IsNull (pb.Image, "#D2"); pb.ImageLocation = "M.gif"; Application.DoEvents (); Assert.AreEqual ("M.gif", pb.ImageLocation, "#E1"); Assert.IsNull (pb.Image, "#E2"); pb.Load (); Application.DoEvents (); Assert.AreEqual ("M.gif", pb.ImageLocation, "#F1"); Assert.IsNotNull (pb.Image, "#F2"); Assert.AreEqual (60, pb.Image.Height, "#F3"); Assert.AreEqual (150, pb.Image.Width, "#F4"); pb.ImageLocation = null; Application.DoEvents (); Assert.IsNull (pb.ImageLocation, "#G1"); Assert.IsNull (pb.Image, "#G2"); pb.ImageLocation = "M.gif"; pb.Load (); pb.ImageLocation = "XYZ.gif"; Application.DoEvents (); Assert.AreEqual ("XYZ.gif", pb.ImageLocation, "#H1"); Assert.IsNotNull (pb.Image, "#H2"); Assert.AreEqual (60, pb.Image.Height, "#H3"); Assert.AreEqual (150, pb.Image.Width, "#H4"); pb.ImageLocation = string.Empty; Application.DoEvents (); Assert.AreEqual (string.Empty, pb.ImageLocation, "#I1"); Assert.IsNull (pb.Image, "#I2"); using (Stream s = this.GetType ().Assembly.GetManifestResourceStream ("32x32.ico")) { pb.Image = Image.FromStream (s); } Application.DoEvents (); Assert.AreEqual (string.Empty, pb.ImageLocation, "#J1"); Assert.IsNotNull (pb.Image, "#J2"); Assert.AreEqual (96, pb.Image.Height, "#J3"); Assert.AreEqual (96, pb.Image.Width, "#J4"); pb.Load ("M.gif"); Application.DoEvents (); Assert.AreEqual ("M.gif", pb.ImageLocation, "#K1"); Assert.IsNotNull (pb.Image, "#K2"); Assert.AreEqual (60, pb.Image.Height, "#K3"); Assert.AreEqual (150, pb.Image.Width, "#K4"); pb.ImageLocation = null; Application.DoEvents (); Assert.IsNull (pb.ImageLocation, "#L1"); Assert.IsNull (pb.Image, "#L2"); f.Dispose (); }
private void populateShapes() { int width = 10; int height = 10; int line = 0; foreach (string photoPath in folderManager.getImages()) { PictureBox picBox = new PictureBox(); picBox.Load(photoPath); picBox.Location = new Point(width, height); picBox.SizeMode = PictureBoxSizeMode.StretchImage; picBox.Size = new System.Drawing.Size(75, 75); picBox.MouseDown += toolManager.shape_MouseDown; Label label = new Label(); label.Text = getName(photoPath); label.Size = new System.Drawing.Size(95, 20); label.Location = new Point(width - 10, height + 75); label.TextAlign = ContentAlignment.MiddleCenter; label.BackColor = Color.Yellow; while (label.Width < System.Windows.Forms.TextRenderer.MeasureText(label.Text, new Font(label.Font.FontFamily, label.Font.Size, label.Font.Style)).Width) { label.Font = new Font(label.Font.FontFamily, label.Font.Size - 0.5f, label.Font.Style); } panelShapes.Controls.Add(label); panelShapes.Controls.Add(picBox); if (line == 0) { width += 100; line++; } else { line = 0; height += 110; width -= 100; } } }
private void LoadImageToPictureBox( PictureBox img ) { this.OpenFile.Filter = "Images | *.jpg; *.png; *.jpeg"; DialogResult result = this.OpenFile.ShowDialog(); if ( result == DialogResult.OK ) { string src = this.OpenFile.FileName; System.IO.FileInfo info = new System.IO.FileInfo( src ); if ( ( info.Length / 1048576 ) < 1.5 ) { img.Load( src ); tMinLogos lg = new tMinLogos(); string[] relation = ( ( string ) img.Tag ).Split( '-' ); lg.Type = Convert.ToInt32( relation[0] ); lg.Dimension = Convert.ToInt32( relation[1] ); lg.Handle = Helper.NameImageRandom( 15 ); lg.Source = src; int indexExists = this._minLogos.FindIndex( x => x.Dimension == lg.Dimension && x.Type == lg.Type ); if ( indexExists < 0 ) this._minLogos.Add( lg ); else this._minLogos[indexExists] = lg; this.btnGuardar.Enabled = true; } else { MetroMessageBox.Show( this, "El Tamaño maximo para una imagen es de 1.5MB.", "LA imagen a superado el tamaño Maximo", MessageBoxButtons.OK, MessageBoxIcon.Warning ); } } }
public SongAlert(string song, string artist, string album, string url) { int ratioX = MaterialSkin.Utilities.DPIMath.ratioX(this); int ratioY = MaterialSkin.Utilities.DPIMath.ratioY(this); BackColor = Color.FromArgb(240, 240, 240); FormBorderStyle = FormBorderStyle.None; Size = new Size(390 * ratioX, 70 * ratioY); Opacity = 0; ShowInTaskbar = false; Load += new EventHandler(Alert_Loaded); PictureBox albumArt = new PictureBox(); try { albumArt.Load(url); } catch (Exception) { // Ignore it }; albumArt.Size = new Size(70 * ratioX, 70 * ratioY); albumArt.SizeMode = PictureBoxSizeMode.StretchImage; Controls.Add(albumArt); int n = 15; Font titleFont = new Font("Calibri", n, FontStyle.Regular); while (TextRenderer.MeasureText(song, titleFont).Width > 312 * ratioX) { if (n < 6) { break; } titleFont = new Font("Calibri", n--, FontStyle.Regular); } Label songTitle = makeLabel(song); songTitle.Location = new Point(78 * ratioX, 8 * ratioY); songTitle.Size = new Size(312 * ratioX, 28 * ratioY); songTitle.Font = titleFont; Controls.Add(songTitle); if (n > 12) { n = 12; } Font infoFont = new Font("Calibri", n, FontStyle.Regular); while (TextRenderer.MeasureText(artist + " - " + album, infoFont).Width > 312 * 2 * ratioX) { if (n < 6) { break; } infoFont = new Font("Calibri", n--, FontStyle.Regular); } Label songInfo = makeLabel(artist + " - " + album); songInfo.Location = new Point(78 * ratioX, 32 * ratioY); if (TextRenderer.MeasureText(artist + " - " + album, infoFont).Width <= 312) { songInfo.Location = new Point(78 * ratioX, 38 * ratioY); } songInfo.AutoSize = false; songInfo.Size = new Size(312 * ratioX, 40 * ratioY); songInfo.Font = infoFont; Controls.Add(songInfo); }
private void DisplayImage(string imageDir, string filename, PictureBox box) { string[] extensions = { ".png", ".jpg" }; foreach (string ext in extensions) { string filePath = Path.Combine(imageDir, filename + ext); if (File.Exists(filePath)) { box.Load(filePath); break; } } }
public static void LoadTiles(D2DMapEditor d2d, Map map, ref Tile[] tileLibrary, ListView lvTileLibrary, ImageList ilTileImages, string fileName) { // load tiles from the saved tile library // clear tile library if (tileLibrary != null) Array.Clear(tileLibrary, 0, tileLibrary.Length); // load tiles /////////////// string pbDirName = Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName); ArrayList tilesArrayList = new ArrayList(); // delete all controls lvTileLibrary.Controls.Clear(); lvTileLibrary.Refresh(); if (Directory.Exists(pbDirName)) { foreach (string f in Directory.GetFiles(pbDirName)) { // load tiles if (Path.GetExtension(f) == ".bmp" || Path.GetExtension(f) == ".jpg" || Path.GetExtension(f) == ".gif" || Path.GetExtension(f) == ".png") tilesArrayList.Add(f.ToString()); } int t = 0; // resize tileLibrary Array.Resize(ref tileLibrary, tilesArrayList.Count); PictureBox pB = null; ListViewItem item = null; foreach (string i in tilesArrayList) { // update tiles library Tile newTile = new Tile(); pB = new PictureBox(); pB.Width = map.TileWidth; pB.Height = map.TileHeight; pB.Name = t.ToString(); pB.Load(i); newTile.TileID = t; newTile.TileName = t.ToString(); newTile.TilePictureBox = pB; tileLibrary[t] = newTile; ilTileImages.Images.Add(pB.Image); item = new ListViewItem(); item.ImageIndex = t; lvTileLibrary.Items.Add(item); t++; } if (pB != null) { ilTileImages.ImageSize = new Size(pB.Width, pB.Height); lvTileLibrary.TileSize = new Size(ilTileImages.ImageSize.Width + TileMargin, ilTileImages.ImageSize.Height + TileMargin); } lvTileLibrary.LargeImageList = ilTileImages; lvTileLibrary.MouseClick += new MouseEventHandler(d2d.tilePicBox_MouseClick); lvTileLibrary.Refresh(); } else { MessageBox.Show(pbDirName + " doesn't exist! This folder is needed for the Tiles Library.", "Cannot Find Folder", MessageBoxButtons.OK, MessageBoxIcon.Error); } string tileLibraryFileName = Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) + "-tile.xml"; FileStream tfs = new FileStream(tileLibraryFileName, FileMode.Open); XmlDocument tr = new XmlDocument(); tr.Load(tfs); XmlNodeList tileList = tr.GetElementsByTagName("Tile"); foreach (XmlNode node in tileList) { XmlElement tileElement = (XmlElement)node; int tileID = Convert.ToInt32(tileElement.Attributes["ID"].InnerText); tileLibrary[tileID].TileName = tileElement.GetElementsByTagName("Name")[0].InnerText; tileLibrary[tileID].TileWidth = Convert.ToInt32(tileElement.GetElementsByTagName("Width")[0].InnerText); tileLibrary[tileID].TileHeight = Convert.ToInt32(tileElement.GetElementsByTagName("Height")[0].InnerText); tileLibrary[tileID].TileWalkable = Convert.ToBoolean(tileElement.GetElementsByTagName("Walkable")[0].InnerText); tileLibrary[tileID].Type = Convert.ToInt32(tileElement.GetElementsByTagName("Type")[0].InnerText); } tfs.Close(); }
public void updateIcon(PictureBox control, IconName name) { control.Load(getIcon(name)); control.BackColor = Color.Transparent; }
public static void AddTiles(D2DMapEditor d2d, Map map, ref Tile[] tileLibrary, ListView lvTileLibrary, ImageList ilTileImages, string folderName) { // add tiles to tile library ArrayList tilesArrayList = new ArrayList(); Cursor.Current = Cursors.WaitCursor; foreach (string f in Directory.GetFiles(folderName)) { // load tiles if (Path.GetExtension(f) == ".bmp" || Path.GetExtension(f) == ".jpg" || Path.GetExtension(f) == ".gif" || Path.GetExtension(f) == ".png") tilesArrayList.Add(f.ToString()); } // delete all controls //lvTileLibrary.Controls.Clear(); //lvTileLibrary.Refresh(); int t = 0; // resize tileLibrary if (tileLibrary != null && tileLibrary.Length > 0) { // add to the library t = tileLibrary.Length; Array.Resize(ref tileLibrary, tilesArrayList.Count + tileLibrary.Length); } else { // load new library Array.Resize(ref tileLibrary, tilesArrayList.Count); } PictureBox pB = null; ListViewItem item = null; foreach (string i in tilesArrayList) { // update tiles library Tile newTile = new Tile(); pB = new PictureBox(); pB.Width = map.TileWidth; pB.Height = map.TileHeight; pB.Name = t.ToString(); pB.Load(i); newTile.TileID = t; newTile.TileName = t.ToString(); newTile.TilePictureBox = pB; tileLibrary[t] = newTile; ilTileImages.Images.Add(pB.Image); item = new ListViewItem(); item.ImageIndex = t; lvTileLibrary.Items.Add(item); t++; } if (pB != null) { ilTileImages.ImageSize = new Size(pB.Width, pB.Height); lvTileLibrary.TileSize = new Size(ilTileImages.ImageSize.Width + TileMargin, ilTileImages.ImageSize.Height + TileMargin); } lvTileLibrary.LargeImageList = ilTileImages; lvTileLibrary.MouseClick += new MouseEventHandler(d2d.tilePicBox_MouseClick); lvTileLibrary.Refresh(); //RenderTiles(map, ref tileLibrary, lvTileLibrary); Cursor.Current = Cursors.Default; }
/// <summary> /// Handles the LoadCompleted event of the pictureBox control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.ComponentModel.AsyncCompletedEventArgs"/> instance containing the event data.</param> /// <remarks>Documented by Dev05, 2007-11-23</remarks> private void ResizePicture(PictureBox pic) { IMedia previousMedia = pic.Tag as IMedia; if (previousMedia == null) return; int maxWidth, maxHeight; ResizeMode mode = pic.Name.Contains("Answer") ? AnswerResizeMode : QuestionResizeMode; switch (mode) { case ResizeMode.Small: maxWidth = Settings.Default.resizeSmall.Width; maxHeight = Settings.Default.resizeSmall.Height; break; case ResizeMode.Medium: maxWidth = Settings.Default.resizeMedium.Width; maxHeight = Settings.Default.resizeMedium.Height; break; case ResizeMode.Large: maxWidth = Settings.Default.resizeLarge.Width; maxHeight = Settings.Default.resizeLarge.Height; break; case ResizeMode.None: default: return; } if (pic.Image.Width <= maxWidth && pic.Image.Height <= maxHeight) return; int width, height; if (pic.Image.Width / maxWidth > pic.Image.Height / maxHeight) { width = maxWidth; height = (int)(maxWidth * 1.0 / pic.Image.Width * pic.Image.Height); } else { height = maxHeight; width = (int)(maxHeight * 1.0 / pic.Image.Height * pic.Image.Width); } string tmpPath = Path.GetTempFileName(); tmpPath = Path.Combine(Path.GetDirectoryName(tmpPath), Path.GetFileNameWithoutExtension(tmpPath) + Path.GetExtension(((IImage)pic.Tag).Extension)); Image newImage = new Bitmap(pic.Image, width, height); newImage.Save(tmpPath, pic.Image.RawFormat); pic.Load(tmpPath); previousMedia.Filename = tmpPath; }
public void ImageLocation_Sync () { Form f = new Form (); PictureBox pb = new PictureBox (); pb.WaitOnLoad = true; f.Controls.Add (pb); f.Show (); Assert.IsNull (pb.ImageLocation, "#A"); pb.ImageLocation = "M.gif"; Assert.AreEqual ("M.gif", pb.ImageLocation, "#B1"); Assert.IsNotNull (pb.Image, "#B2"); Assert.AreEqual (60, pb.Image.Height, "#B3"); Assert.AreEqual (150, pb.Image.Width, "#B4"); using (Stream s = this.GetType ().Assembly.GetManifestResourceStream ("32x32.ico")) { pb.Image = Image.FromStream (s); } Assert.AreEqual ("M.gif", pb.ImageLocation, "#C1"); Assert.IsNotNull (pb.Image, "#C2"); Assert.AreEqual (96, pb.Image.Height, "#C3"); Assert.AreEqual (96, pb.Image.Width, "#C4"); pb.ImageLocation = null; Assert.IsNull (pb.ImageLocation, "#D1"); Assert.IsNotNull (pb.Image, "#D2"); Assert.AreEqual (96, pb.Image.Height, "#D3"); Assert.AreEqual (96, pb.Image.Width, "#D4"); pb.ImageLocation = "M.gif"; Assert.AreEqual ("M.gif", pb.ImageLocation, "#E1"); Assert.IsNotNull (pb.Image, "#E2"); Assert.AreEqual (60, pb.Image.Height, "#E3"); Assert.AreEqual (150, pb.Image.Width, "#E4"); pb.Load (); Assert.AreEqual ("M.gif", pb.ImageLocation, "#F1"); Assert.IsNotNull (pb.Image, "#F2"); Assert.AreEqual (60, pb.Image.Height, "#F3"); Assert.AreEqual (150, pb.Image.Width, "#F4"); pb.ImageLocation = null; Assert.IsNull (pb.ImageLocation, "#G1"); Assert.IsNull (pb.Image, "#G2"); using (Stream s = this.GetType ().Assembly.GetManifestResourceStream ("32x32.ico")) { pb.Image = Image.FromStream (s); } Assert.IsNull (pb.ImageLocation, "#H1"); Assert.IsNotNull (pb.Image, "#H2"); Assert.AreEqual (96, pb.Image.Height, "#H3"); Assert.AreEqual (96, pb.Image.Width, "#H4"); pb.Load ("M.gif"); Assert.AreEqual ("M.gif", pb.ImageLocation, "#I1"); Assert.IsNotNull (pb.Image, "#I2"); Assert.AreEqual (60, pb.Image.Height, "#I3"); Assert.AreEqual (150, pb.Image.Width, "#I4"); pb.ImageLocation = string.Empty; Assert.AreEqual (string.Empty, pb.ImageLocation, "#J1"); Assert.IsNull (pb.Image, "#J2"); pb.ImageLocation = "M.gif"; Assert.AreEqual ("M.gif", pb.ImageLocation, "#K1"); Assert.IsNotNull (pb.Image, "#K2"); Assert.AreEqual (60, pb.Image.Height, "#K3"); Assert.AreEqual (150, pb.Image.Width, "#K4"); try { pb.ImageLocation = "XYZ.gif"; Assert.Fail ("#L1"); } catch (FileNotFoundException ex) { Assert.AreEqual (typeof (FileNotFoundException), ex.GetType (), "#L2"); Assert.IsNull (ex.InnerException, "#L3"); Assert.IsNotNull (ex.Message, "#L4"); } Assert.AreEqual ("XYZ.gif", pb.ImageLocation, "#M1"); Assert.IsNotNull (pb.Image, "#M2"); Assert.AreEqual (60, pb.Image.Height, "#M3"); Assert.AreEqual (150, pb.Image.Width, "#M4"); f.Dispose (); }
private void AddTabImage(string tabname, string tag, string file) { TabPage tab = new TabPage(tabname); PictureBox pic = new PictureBox(); pic.Load(file); //pic.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; pic.SizeMode = PictureBoxSizeMode.AutoSize; pic.SizeMode = PictureBoxSizeMode.Zoom; pic.Tag = 1; tab.Controls.Add(pic); tab.MouseWheel += new MouseEventHandler(tab_ImageMouseWheel); tab.Tag = tag; tabDocs.TabPages.Add(tab); pic.Left = (tab.Width - pic.Width) / 2; pic.Top = (tab.Height - pic.Height) / 2; tabDocs.SelectedIndex = tabDocs.TabPages.Count - 1; UpdateButtons(); }
[Test] // Load (String) public void Load2_Url_Null () { PictureBox pb = new PictureBox (); try { pb.Load ((string) null); Assert.Fail ("#1"); } catch (InvalidOperationException ex) { // ImageLocation must be set Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2"); Assert.IsNull (ex.InnerException, "#3"); Assert.IsNotNull (ex.Message, "#4"); } }
void bs_PositionChanged(object sender, EventArgs e) { dynamic d = this.bs.Current; this.flowLayoutPanel1.Controls.Clear(); for (int i=0; i<=d.ImageFiles.Length-1;i++) { PictureBox p = new PictureBox(); p.Width = 80; p.Height = 50; p.BorderStyle = BorderStyle.Fixed3D; p.Load(d.ImageFiles[i]); p.SizeMode = PictureBoxSizeMode.StretchImage; this.flowLayoutPanel1.Controls.Add(p); // Application.DoEvents(); } }
public PictureBox GetOPPicture(string tmpThread) { PictureBox pb = new PictureBox(); string thread = tmpThread.Replace("thread/", ""); string html = GetHtmlCodethread(board, thread); if (html.Length > 0) { string a = html.Substring(html.IndexOf("<a class=\"fileThumb\" href=\""), html.Length - html.IndexOf("<a class=\"fileThumb\" href=\"")); a = a.Substring(0, a.IndexOf("\" target")); a = a.Replace("<a class=\"fileThumb\" href=\"", ""); a = "http:" + a; try { pb.Load(a); pb.SizeMode = PictureBoxSizeMode.StretchImage; } catch { } return pb; } else { return null; } }