// Form1 事件
public static Form2 f2;
private void button1_Click(object sender, EventArgs e)
{
if (f2 == null)
{
f2 = new Form2();
f2FormBorderStyle = SystemWindowsFormsFormBorderStyleNone; // 设置边框为 None
f2WindowState = FormWindowStateMaximized; // 最大化
f2TopMost = true; // 置顶
f2KeyPreview = true; // 允许窗体先收到键盘事件
f2KeyUp += new KeyEventHandler(Form2_KeyUp); // 指定键盘按下事件
f2Show(); // 显示 Form 2
}
}
private void Form2_KeyUp(object sender, KeyEventArgs e)
{
if (eKeyCode == KeysEscape) //“Esc” 按键退出全频
{
f2Close(); // 关闭 Form2 (或者还原窗口也行)
f2 = null;
}
}
这种现象我也遇到过,主要的原因是因为窗体上的控件太多,而且过多的设置了控件的Ancher属性,使窗体重绘的控件过多,或者是设置窗体的TransparencyKey的属性,我的解决方案就是用的画虚框的方法,那个程序已经找不着了,给你简单写了个右边框拉伸的,代码如下
//不要设置窗体的TransparencyKey的属性
Rectangle bolderRight;
Rectangle drawRect;
bool draw = false;
int bolderWidth = 4;
int lastWidth = -32000;
private void Form1_Load(object sender, EventArgs e)
{
bolderRight = new Rectangle(thisWidth - bolderWidth, 0, bolderWidth, thisHeight);
drawRect = new Rectangle(thisLocation, thisSize);
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (eButton == MouseButtonsLeft || bolderRightContains(eLocation))
{
thisCursor = CursorsSizeWE;
draw = true;
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (bolderRightContains(eLocation))
thisCursor = CursorsSizeWE;
else
thisCursor = CursorsDefault;
if (draw)
{
if (lastWidth != -32000)//擦出上一次绘制的边框
ControlPaintDrawReversibleFrame(new Rectangle(drawRectLocation, new Size(lastWidth, drawRectHeight)), ColorBlack, FrameStyleDashed);
drawRectWidth = MousePositionX - thisLeft;
ControlPaintDrawReversibleFrame(drawRect, ColorBlack, FrameStyleDashed);
lastWidth = drawRectWidth;
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
draw = false;
ControlPaintDrawReversibleFrame(drawRect, ColorBlack, FrameStyleDashed);
thisSize = drawRectSize;
lastWidth = -32000;
}
private void Form1_Resize(object sender, EventArgs e)
{
bolderRight = new Rectangle(thisWidth - bolderWidth, 0, bolderWidth, thisHeight);
drawRect = new Rectangle(thisLocation, thisSize);
}
以上就是关于C# WinForm 实现全屏效果全部的内容,包括:C# WinForm 实现全屏效果、Winform改变窗口大小问题、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)