我需要在鼠标位于PictureBox上方并且已经单击并按住鼠标按钮时触发事件.
问题:
MouseDown和MouseEnter事件处理程序不能很好地协同工作.
例如,一旦单击并按住鼠标按钮,C#将触发MouseDown事件处理程序,但是当光标移动到PictureBox上时,MouseEnter事件不会触发,直到鼠标按钮被重新发布.
我有个问题:
我有3个图片框,有3个不同的图像,如图像
我可以设置为pictureBox3所以两个图像看起来相同.....

编辑: 我想在pictureBox2上移动pictureBox3,
因此没有选项将它们合并到单个图像
我如何知道图片框的图像何时发生变化?
是否有图像更改事件?
我试图使它成为PictureBox控件中的图像将根据窗口的大小自动调整其大小,但保持纵横比.到目前为止,只是设置SizeMode为StretchImage使图像拉伸以适合整个PictureBox控件.这忽略了纵横比,这不是我想要的.
是否可以保持纵横比,但仍然可以将图像拉伸到表格尺寸变化时可以动态移动的最大值?是否可以这样做,并让它仍然居中?我想每次调整窗口大小时我都可以在内存中重新创建图像,但这似乎是一个坏主意.
我想icon file在一个图片框中显示.我正在使用此代码来设置图像.
pictureBox1.Image = new Icon(openFileDialog.FileName, new Size(48, 48)).ToBitmap();
Run Code Online (Sandbox Code Playgroud)
但我得到了这个例外.
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, IntPtr destination, Int32 length)
at System.Drawing.Icon.ToBitmap()
Run Code Online (Sandbox Code Playgroud)
如何克服这个问题?
谢谢.
是否有一种简单而实用的方法来缩放图片框中的图像,包括滚动条?
目前,我在面板中使用了一个自动滚动激活的图片框.要进行缩放,我会放大图片框并使用面板上的滚动条移动它.问题是,它表现得很奇怪.例如:如果放大到远,则上下左边的边框和图像的边距越来越大.
这是缩放方法.我是从这里得到的.
private void ZoomInOut(bool zoom)
{
//Zoom ratio by which the images will be zoomed by default
int zoomRatio = 10;
//Set the zoomed width and height
int widthZoom = pictureBox_viewer.Width * zoomRatio / 100;
int heightZoom = pictureBox_viewer.Height * zoomRatio / 100;
//zoom = true --> zoom in
//zoom = false --> zoom out
if (!zoom)
{
widthZoom *= -1;
heightZoom *= -1;
}
//Add the width and height to the picture box dimensions
pictureBox_viewer.Width …Run Code Online (Sandbox Code Playgroud) PictureBox我的Windows窗体应用程序上有一个.
我在其中加载了一张图片,并Paint在代码中启用了该事件.它绘制一个矩形.
像这样:
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics gr = e.Graphics;
Pen p = new Pen(Color.Red);
p.Width = 5.0f;
gr.DrawRectangle(p, 1, 2, 30, 40);
}
Run Code Online (Sandbox Code Playgroud)
然后我点击"保存"按钮:
private void button2_Click(object sender, EventArgs e)
{
pictureBox1.Image.Save(@"C:\Documents and Settings\tr1g3800\Desktop\WALKING\30P\100000test.jpg",ImageFormat.Jpeg);
}
Run Code Online (Sandbox Code Playgroud)
但是保存的文件永远不会包含我绘制的矩形.
有谁有想法吗?
有时候,我有一个图片盒可以说是100x100.但它显示的图像实际上是100x400.
我不想增加图片框本身的大小.相反,我想创建一个垂直滚动条(或根据需要水平).
我在工具箱中找不到滚动条,所以我想我必须编写它.但是,怎么样?而且我仍然想知道我是否没有犯错并且没有看到工具箱中的滚动条.我道歉:(
我正在尝试为彩色图像添加文本比例.agcScale.jpg图像(下方)是顶部和底部的2个winform标签,左侧和右侧是2个winform图片框.完全相同的代码用于在右侧和左侧图片框中生成字符串,唯一的区别是pictureBoxAgcVscale仅包含字符串.为什么pictureBoxAgc中的DrawString看起来不错,但pictureBoxAgcVscale中的DrawString看起来如此糟糕?我可以通过为每个像素执行bmp.SetPixel来修复pictureBoxAgcVscale,但这似乎是解决此问题的错误方法.

private void DisplayAgcVscale(double min, double max)
{
var bmp = new Bitmap(pictureBoxAgcVscale.Width, pictureBoxAgcVscale.Height);
var c = (max - min) / bmp.Height;
using (var g = Graphics.FromImage(bmp))
{
var font = new Font("Microsoft Sans Serif", 8.25F);
var y1 = bmp.Height / 10;
for (var y = y1; y < bmp.Height; y += y1)
{
var agc = y * c + min;
var text = agc.ToString("#0.000V");
var h = bmp.Height - y - font.Height / 2;
g.DrawString(text, font, Brushes.Black, 0, …Run Code Online (Sandbox Code Playgroud) 我已经尝试了很多,我怎么能将图像从SQL Server加载到图片框,但我找不到非常有用的材料.
首先,我借助以下查询将图像保存到数据库中:
insert into imageTest (pic_id, pic)
values(1, 'D:\11.jpg')
Run Code Online (Sandbox Code Playgroud)
现在我想将图像加载到图片框中.
picturebox ×10
c# ×9
winforms ×8
.net ×3
autoscroll ×1
drawstring ×1
events ×1
icons ×1
image ×1
mouse ×1
scrollbar ×1
vb.net ×1
zooming ×1