上下文菜单和菜单项的图像从右到左 [英] to be Right to Left of an image for context menue and menu item
本文介绍了上下文菜单和菜单项的图像从右到左的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好
我有这个代码。图像和文本位于左侧,但我希望它们位于右侧(从右到左)。怎么样?
Hello
I have this code. The Image and text are in left side but I want that they be in right side (Right to Left). How?
private void menuSubItemContextQYes_DrawItem(object sender, DrawItemEventArgs e)
{
Rectangle rcImage = e.Bounds;
Image image = Image.FromFile(Application.StartupPath + @"\Icons\DeleteIcon.jpg");
rcImage.Width = image.Width/8;
rcImage.Height = image.Height/8;
e.Graphics.DrawImage(image, rcImage);
MenuItem mi = (MenuItem)sender;
Font menuFont = SystemInformation.MenuFont;
SolidBrush menuBrush = new SolidBrush(SystemColors.MenuText);
StringFormat strfmt = new StringFormat();
strfmt.LineAlignment = System.Drawing.StringAlignment.Near;
Rectangle rcText = e.Bounds;
rcText.X += rcImage.Width;
e.Graphics.DrawString(mi.Text, menuFont, menuBrush, e.Bounds.Left - image.Width/8, e.Bounds.Bottom + ((e.Bounds.Height - menuFont.Height) / 2), strfmt);
}
private void menuSubItemContextQYes_MeasureItem(object sender, MeasureItemEventArgs e)
{
MenuItem mi = (MenuItem)sender;
Font menuFont = SystemInformation.MenuFont;
StringFormat strfmt = new StringFormat();
strfmt.LineAlignment = System.Drawing.StringAlignment.Near;
SizeF sizef = e.Graphics.MeasureString(mi.Text, menuFont, 1000, strfmt);
Image image = Image.FromFile(Application.StartupPath + @"\Icons\DeleteIcon.jpg");
e.ItemWidth = (int)Math.Ceiling(sizef.Width) + image.Width / 8;
e.ItemHeight = (int)Math.Ceiling(sizef.Height) + image.Height / 8;
}
推荐答案
命令e.graphice.drawimage在位置绘制图像,由矩形rcImage的坐标。在这里,ypu只能将矩形的X位置更改为e.bounds.width-image.Width / 8.
与e相同。 graphics.drawstring-command。
也许你自己试试......
The command e.graphice.drawimage draws the Image at the Position, defined by the coordinates of the rectangle rcImage. Here ypu only havbe to change the X-Position of the rectangle to e.bounds.width-image.Width/8.
The same is it with the e.graphics.drawstring-command.
Perhaps you try it by yourself ...
这篇关于上下文菜单和菜单项的图像从右到左的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文