本文介绍了如何使用右键菜单项到图片框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我右键单击图片框时,通过使用上下文菜单项,我显示了像saveImageAs这样的标签。

问题:当我右键单击图片框时,它会显示saveImageAs,当我点击saveImageAs时我会点击



private void saveImageAsToolStripMenuItem_Click(对象发件人,EventArgs e)

{

//我应该使用什么而不是点击来点击form_Mouseclick



pictureBox1.Click + = form_MouseClick;

pictureBox2.Click + = form_MouseClick;



}



这里我应该使用什么代替pictureBox1.click才能点击form_MouseClick



如果有人可以提供帮助,我会非常感激。



private void saveImageAsToolStripMenuItem_Click(object sender,EventArgs e)

{

pictureBox1.Click + = form_MouseClick;

pictureBox2.Click + = form_MouseClick;



}



private void form_MouseClick(对象发送者,MouseEventArgs e)

{

PictureBox pb =发送者作为PictureBox;

SaveFileDialog sfd = new SaveFileDialog();

sfd.Filter =Images | * .png; * .bmp; *。jpg;

if(sfd.ShowDialog()== System.Windows.Forms.DialogResult .OK)

{

string filepath = System.IO.Path.GetExtension(sfd.FileName);

}

if(pb!= null&& sfd.FileName!= null)

{

Image im = pb.Image;

SaveImage(im,sfd.FileName);

}

} $ / $


private static void SaveImage(Image im,string destPath)

{

im.Save(destPath) ,System.Drawing.Imaging.ImageFormat.Png);

}



我尝试了什么:



我试过



private void saveImageAsToolStripMenuItem_Click(object sender,EventArgs e)

{

pictureBox1.MouseClick + = form_MouseClick;

pictureBox2.MouseClick + = form_MouseClick;



}

when I right-click on a picturebox, by using context menu items i am showing the labels like saveImageAs.
problem: when i right click on a picture box, it shows saveImageAs, when i click saveImageAs i will hit

private void saveImageAsToolStripMenuItem_Click(object sender, EventArgs e)
{
//what should i use instead of click to hit form_Mouseclick

pictureBox1.Click += form_MouseClick;
pictureBox2.Click += form_MouseClick;

}

here what should i use instead of pictureBox1.click to hit form_MouseClick

If anyone could help I would be most greatful.

private void saveImageAsToolStripMenuItem_Click(object sender, EventArgs e)
{
pictureBox1.Click += form_MouseClick;
pictureBox2.Click += form_MouseClick;

}

private void form_MouseClick(object sender, MouseEventArgs e)
{
PictureBox pb = sender as PictureBox;
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Images|*.png;*.bmp;*.jpg";
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string filepath = System.IO.Path.GetExtension(sfd.FileName);
}
if (pb != null && sfd.FileName != null)
{
Image im = pb.Image;
SaveImage(im, sfd.FileName);
}
}

private static void SaveImage(Image im, string destPath)
{
im.Save(destPath, System.Drawing.Imaging.ImageFormat.Png);
}

What I have tried:

I tried

private void saveImageAsToolStripMenuItem_Click(object sender, EventArgs e)
{
pictureBox1.MouseClick+= form_MouseClick;
pictureBox2.MouseClick+= form_MouseClick;

}

推荐答案

if (e.Button == Windows.Forms.MouseButtons.Right) {  }


这篇关于如何使用右键菜单项到图片框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 15:58