picturebox

Displaying an icon in a picturebox

百般思念 提交于 2019-12-18 04:41:37
问题 I am trying to display icon file in a picture box. I'm using this code to set the image. pictureBox1.Image = new Icon(openFileDialog.FileName, new Size(48, 48)).ToBitmap(); But I'm getting this exception. System.ArgumentOutOfRangeException: Requested range extends past the end of the array. at System.Runtime.InteropServices.Marshal.CopyToNative(Object source, Int32 startIndex, IntPtr destination, Int32 length) at System.Runtime.InteropServices.Marshal.Copy(Byte[] source, Int32 startIndex,

C#: Simple and functional way to zoom picturebox images with scroll bars

扶醉桌前 提交于 2019-12-18 04:41:07
问题 Is there a simple and functional way to zoom an image in a picturebox including scroll bars? At the moment, I use a picture box in a panel with auto scroll activated. To zoom, I enlarge the picturebox and move it with the scroll bars on the panel. The problem is, that it behaves strange. For example: If you zoom in to far, the margin between the upper and left form border and the image get's bigger and bigger. That's the zooming method. I got it from here. private void ZoomInOut(bool zoom) {

Load a bitmap image into Windows Forms using open file dialog

走远了吗. 提交于 2019-12-18 03:56:55
问题 I need to open the bitmap image in the window form using open file dialog (i will load it from drive). The image should fit in the picture box. Here is some code i have tried but got error! private void button1_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "Open Image"; dlg.Filter = "bmp files (*.bmp)|*.bmp"; if (dlg.ShowDialog() == DialogResult.OK) { PictureBox PictureBox1 = new PictureBox(); PictureBox1.Image(dlg.FileName); } dlg.Dispose(); } 回答1

Photoshop like background on transparent image

限于喜欢 提交于 2019-12-17 21:22:20
问题 I'm making a graphics editor for my class project and i want to make so that when, for example a user loads a picture in to the editor or or draw something in the PictureBox, all the alpha parts are shown the chessboard like background. My idea is that when I create a PictureBox with transparent background set, I create another one behind it, set its BackColor to white and add grey images 50x50, alternately horizontally and vertically. Is that a good approach to the problem? If, not do You

How do you access the name of the image in a picturebox in Visual Studio using C#

谁都会走 提交于 2019-12-17 21:11:19
问题 I have a program which has 16 grid tiles using picturebox but only uses 5 images, the rest of the tiles are just a black image. I would like to be able to tell which image the 'user' clicks on. I have a method called image_Click(object sender, EventArgs e) I have an if statement inside this method that states: if (peckedSquare.BackColor == Color.Black) { System.Diagnostics.Debug.WriteLine("Pecked a black square"); return; } This sends a String that lets me know when a black square has been

Is this possible to have triangular PictureBox instead of the rectangular one?

£可爱£侵袭症+ 提交于 2019-12-17 20:43:16
问题 Is this possible to have triangular PictureBox control in windows forms instead of the rectangular one? 回答1: You have some options, for example: You can set the region of control to a triangle. You can only paint in a triangular area of the control. Example 1 In this example, the region of control limited to a triangular shape. public class TriangularPictureBox:PictureBox { protected override void OnPaint(PaintEventArgs pe) { using (var p = new GraphicsPath()) { p.AddPolygon(new Point[] { new

Change PictureBox's image to image from my resources?

孤人 提交于 2019-12-17 18:27:10
问题 How do I set a PictureBox image to an image from my resources? (I tried this without success: pictuerbox.Image = "img_location"; ) 回答1: If you loaded the resource using the visual studio UI, then you should be able to do this: picturebox.Image = project.Properties.Resources.imgfromresource 回答2: Ken has the right solution, but you don't want to add the picturebox.Image.Load() member method. If you do it with a Load and the ImageLocation is not set, it will fail with a "Image Location must be

Moving a control by dragging it with the mouse in C#

六月ゝ 毕业季﹏ 提交于 2019-12-17 18:09:08
问题 I'm trying to move the control named pictureBox1 by dragging it around. The problem is, when it moves, it keeps moving from a location to another location around the mouse, but it does follow it... This is my code. and I would really appreciate it if you could help me public partial class Form1 : Form { public Form1() { InitializeComponent(); } bool selected = false; private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { selected = true; } private void pictureBox1_MouseMove

How to rotate image in picture box

只愿长相守 提交于 2019-12-17 14:53:34
问题 I am making a winforms application. One of the features I hope to implement is a rotating gear on the home form. When the home form is loaded, you should hover over the picture of the gear, and it should rotate in place. But all I have so far is the RotateFlip and that just flips the picture. Is there a way to make the gear turn in place when the mouse is hovering over it? The code I have so far is: Bitmap bitmap1; public frmHome() { InitializeComponent(); try { bitmap1 = (Bitmap)Bitmap

How to zoom an image in&out in C#?

天大地大妈咪最大 提交于 2019-12-17 10:53:40
问题 I want to implement zoom for an image. I don't want to resize the PictureBox, but the image itself. How do I do this? 回答1: One solution is: Create new image of the desired size (for example 200% or 50% of original image size) Draw original image to new image using Graphics.DrawImage(Image, Rectangle);, which draws the given image to the new image at the given position with the given size Set new image as source for the PictureBox Another way is to simple create a new bitmap instance like that