I am using Windows Form project. In my MDI Parent Form that I want to show my company logo at the right side corner. So I have drag a picturebox and set the image.
我正在使用Windows窗体项目。在我的MDI父表单中,我想在右侧角显示我的公司徽标。所以我拖动了一个图片框并设置了图像。
But I am not success my requirement, The image not in correct position. I have tried padding also. Dock is increase my image height to full form height. So Its also not help me.
但是我的要求不成功,图像位置不正确。我也试过填充。 Dock将我的图像高度增加到完整形状高度。所以它也没有帮助我。
Before Running the Solution. (I want this as a run time)..
在运行解决方案之前。 (我希望这是一个运行时间)..
At the Time of Solution Running. (Unwanted Space in Right side)
在解决方案运行时。 (右侧不需要的空间)
And MDI Form is Maximized at running time. with the help of below code.
MDI表格在运行时最大化。在下面的代码的帮助下。
this.WindowState = FormWindowState.Maximized;
3 个解决方案
#1
3
You will have to set Anchor property of picturebox to Top, Right by default its set to Top, Left
您必须将picturebox的Anchor属性设置为Top,右边默认设置为Top,Left
#2
2
This isn't going to work, you'll discover soon when you start creating MDI client windows. The picture box is always on top of the client windows. What is required is drawing the image in the MDI client window, the dark gray window in your screenshots. That takes a fair amount of unusual code, you have to get a reference to that control so you can implement your own Paint event for it. You also need to be aware that the window size changes so your can repaint the image in the new location. And you have to do something about the flicker you normally see. Make your code look similar to this:
这不起作用,当您开始创建MDI客户端窗口时,您很快就会发现。图片框始终位于客户端窗口的顶部。所需要的是在MDI客户端窗口中绘制图像,即屏幕截图中的深灰色窗口。这需要相当多的异常代码,您必须获得对该控件的引用,以便您可以为它实现自己的Paint事件。您还需要注意窗口大小的变化,以便您可以在新位置重新绘制图像。你必须对你通常看到的闪烁做些什么。使您的代码看起来类似于:
using System.Reflection;
...
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
foreach (Control ctl in this.Controls) { // Find the MDI client window
if (ctl is MdiClient) {
ctl.Paint += new PaintEventHandler(MdiClient_Paint);
ctl.Resize += delegate { ctl.Invalidate(); };
// Hackorama to avoid flicker:
var dblBuf = ctl.GetType().GetProperty("DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance);
dblBuf.SetValue(ctl, true, null);
break;
}
}
}
void MdiClient_Paint(object sender, PaintEventArgs e) {
var client = (MdiClient)sender;
using (var bmp = Properties.Resources.Logo) { // change this
e.Graphics.DrawImage(bmp, new Point(client.ClientSize.Width - bmp.Width, 0));
}
}
}
#3
1
Put picture box in to a container and Dock the Container first. Then Container Only Dock to right. And put and Image to picture box.
将图片框放入容器中并先将Dock对接。然后Container Only Dock到右边。并把图像放到图片框中。
#1
3
You will have to set Anchor property of picturebox to Top, Right by default its set to Top, Left
您必须将picturebox的Anchor属性设置为Top,右边默认设置为Top,Left
#2
2
This isn't going to work, you'll discover soon when you start creating MDI client windows. The picture box is always on top of the client windows. What is required is drawing the image in the MDI client window, the dark gray window in your screenshots. That takes a fair amount of unusual code, you have to get a reference to that control so you can implement your own Paint event for it. You also need to be aware that the window size changes so your can repaint the image in the new location. And you have to do something about the flicker you normally see. Make your code look similar to this:
这不起作用,当您开始创建MDI客户端窗口时,您很快就会发现。图片框始终位于客户端窗口的顶部。所需要的是在MDI客户端窗口中绘制图像,即屏幕截图中的深灰色窗口。这需要相当多的异常代码,您必须获得对该控件的引用,以便您可以为它实现自己的Paint事件。您还需要注意窗口大小的变化,以便您可以在新位置重新绘制图像。你必须对你通常看到的闪烁做些什么。使您的代码看起来类似于:
using System.Reflection;
...
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
foreach (Control ctl in this.Controls) { // Find the MDI client window
if (ctl is MdiClient) {
ctl.Paint += new PaintEventHandler(MdiClient_Paint);
ctl.Resize += delegate { ctl.Invalidate(); };
// Hackorama to avoid flicker:
var dblBuf = ctl.GetType().GetProperty("DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance);
dblBuf.SetValue(ctl, true, null);
break;
}
}
}
void MdiClient_Paint(object sender, PaintEventArgs e) {
var client = (MdiClient)sender;
using (var bmp = Properties.Resources.Logo) { // change this
e.Graphics.DrawImage(bmp, new Point(client.ClientSize.Width - bmp.Width, 0));
}
}
}
#3
1
Put picture box in to a container and Dock the Container first. Then Container Only Dock to right. And put and Image to picture box.
将图片框放入容器中并先将Dock对接。然后Container Only Dock到右边。并把图像放到图片框中。