如何恢复在C#.Net(2.0)中将formboderstyle更改为"none"后丢失的Windows窗体的某些属性 [英] How to regain some of properties of windows form which are lost after changing formboderstyle to 'none' in C#.Net(2.0)

查看:60
本文介绍了如何恢复在C#.Net(2.0)中将formboderstyle更改为"none"后丢失的Windows窗体的某些属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在
学习了自定义形状的表单和按钮
http://msdn.microsoft.com/en-us/library/aa289517 (VS.71).aspx#vbtchshapedwindowsformscontrolsinvisualstudionetanchor1


在那里说明了如何保留某些属性(如窗体拖动),但我想知道如何重新获得此处未指定的窗体调整大小属性.

如何重新获得此属性,并且当我们将鼠标光标移到这些自定义窗体的边框时,鼠标光标应更改为调整普通窗体的大小.此外,在任务栏中,如果以正常形式单击鼠标右键,它将在上下文菜单中提供诸如关闭",还原",最小化"等选项.当我们将"formborderstyle"属性更改为"none"时,此属性也会丢失.那么如何也获得此属性.

我想知道将"formborderstlye"设置为"none"后如何重新获得Windows窗体(在C#.Net中)的某些属性.

I learned custom shaped forms and buttons at

http://msdn.microsoft.com/en-us/library/aa289517(VS.71).aspx#vbtchshapedwindowsformscontrolsinvisualstudionetanchor1


there how to retain some properties like form dragging is explained but I wanted to know how to re-gain form resizing property which is not specified there.

How can be this property be re-gained and as we move mouse cursor to these custom form''s border the mouse cursor should change as for resizing in normal forms. Moreover in taskbar if in normal forms we give mouse right-click it gives options in context menu like "close","restore","minimize" etc. this property also gets lost when we change "formborderstyle" property to "none". So how to also gain this property.

I wanted to know how some of these properties of Windows forms(in C#. Net) could be regained after setting the "formborderstlye" to "none".

推荐答案

So ,我认为您无法使右键单击菜单项看起来完全一样.主要原因是我看不到在任务栏顶部下方绘制contextMenuStrip的方法.但是,您可以做的是使用所需的项创建自己的ContextMenuStrip.然后,您重写WndProc方法并显示ContextMenuStrip.看起来像:

So, I don''t think you can get the right-click menu item to look exactly the same. The main reason is that I can''t see a way to draw the contextMenuStrip below the top of the taskbar. But, what you can do is create your own ContextMenuStrip with the items you want. Then, you override the WndProc method and show the ContextMenuStrip. It looks like:

private const int WMTaskbarRClick = 0x0313;

protected override void WndProc(ref Message m)
{
    switch (m.Msg)
    {
        case WMTaskbarRClick:
            contextMenuStrip1.Show(Cursor.Position);
            break;
        default:
            base.WndProc(ref m);
            break;
    }
}



调整表格大小有点棘手.您必须首先确定要用于调整大小的区域.完成此操作后,您需要钩住鼠标移动并查看光标是否在该区域中.如果是,则更改光标.然后,如果在更改光标的同时用户按下鼠标,则开始拖动.

矩形很容易.我已完成以下操作:



Resizing the form is a bit trickier. You have to first decide on a region that you will be using to allow the resize. Once you''ve done that, you need to hook the mouse move and see if the cursor is in that region. If it is, then you change the cursor. Then, if the user mouses down while the cursor is changed, you start dragging.

It''s easy for a rectangular form. I''ve done the following:

private bool dragging = false;
private Point offset;
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
    if (!dragging)
    {
        if (e.X < this.Width && e.X > this.Width - 10
            && e.Y < this.Height && e.Y > this.Height - 10)
        {
            offset = new Point(this.Width - e.X, this.Height - e.Y);
            this.Cursor = Cursors.SizeNWSE;
        }
        else
        {
            this.Cursor = Cursors.Default;
        }
    }
    else
    {
        this.Width = e.X + offset.X;
        this.Height = e.Y + offset.Y;
    }
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
    if (this.Cursor == Cursors.SizeNWSE)
        dragging = true;
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
    if (this.Cursor == Cursors.SizeNWSE)
        dragging = false;
}



我基本上已经在右下角定义了一个区域,用户可以在该区域上移动鼠标,然后调整其大小.



I''ve basically defined a region to the bottom right where the user can mouse over and then resize it.


Hi Vikram

这非常简单,添加最小化"和最大化"按钮
在Windows窗体上以及这些按钮的按钮单击事件上等如下所示

Hi Vikram

This is very simple, add the buttons for "Minimise" and Maximise
etc on the windowsform and on button click event of these buttons write as below

private void buttonMax_Click(object sender, EventArgs e)
{
  WindowState = FormWindowState.Maximised;
}

private void buttonMin_Click(object sender, EventArgs e)
{
  WindowState = FormWindowState.Minimized;
}


这篇关于如何恢复在C#.Net(2.0)中将formboderstyle更改为"none"后丢失的Windows窗体的某些属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆