【问题标题】:Winform and WPF form/window borderWinform 和 WPF 窗体/窗口边框
【发布时间】:2012-11-23 11:00:41
【问题描述】:

我一直在处理这个问题,我不知道如何处理。

我有一个同时包含 Windows 窗体和 WPF 窗体的项目。

我希望每个表单都像这样显示(它是 WPF 表单):

WPF = http://imageshack.us/photo/my-images/545/wpfk.png/

我实现了这个 windows style = none 和 canresize = yes。我实际上不希望它被调整大小。我只想要表格周围的细边框。但是如果我把 canresize = false 我失去了边界。我还希望能够在屏幕中移动窗口,而不是在那个地方保持静止。

我的 winforms 也需要所有这些。

Winforms: WINFORM = http://imageshack.us/photo/my-images/836/winforms.png/

我希望你们明白我需要什么。从图形上看,它必须像第一张图片一样。

【问题讨论】:

  • 如果e.OriginalSource是窗口边框,你能e.CancelMouseDown事件吗?
  • 这可以在我的 WPF 窗口中工作,其中 sizable = true 使边框可见,但在 winforms 中我没有该属性。
  • 啊,我现在更好地理解了你的问题。不幸的是,我对 Winforms 了解不多,因为我更喜欢尽可能使用 WPF,所以无法帮助您

标签: c# wpf winforms forms border


【解决方案1】:

我不确定它是否有帮助,但您可以为此创建表单集合。 (一)

http://support.microsoft.com/kb/815707/en-us

【讨论】:

    【解决方案2】:

    解决方案:将此代码粘贴到您的表单或基本表单中。

    private const int WS_SYSMENU = 0x80000;
    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
            cp.Style &= ~WS_SYSMENU;
            return cp;
        }
    }
    

    感谢 Killercam 的帮助!

    WPF 窗口解决方案:

    public MainWindow()
        {
            SourceInitialized += Window_SourceInitialized;
            InitializeComponent();
        }
    
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    
        private void button3_Click(object sender, RoutedEventArgs e)
        {
            this.WindowState = WindowState.Minimized;
        }
    
        private void Window_SourceInitialized(object sender, EventArgs e)
        {
            WindowInteropHelper wih = new WindowInteropHelper(this);
            int style = GetWindowLong(wih.Handle, GWL_STYLE);
            SetWindowLong(wih.Handle, GWL_STYLE, style & ~WS_SYSMENU);
        }
    
        private const int GWL_STYLE = -16;
        private const int WS_SYSMENU = 0x00080000;
    
        [DllImport("user32.dll")]
        private extern static int SetWindowLong(IntPtr hwnd, int index, int value);
        [DllImport("user32.dll")]
        private extern static int GetWindowLong(IntPtr hwnd, int index);
    

    【讨论】:

      【解决方案3】:

      您只需将设计器中的 WinForms FormBorderStyle 属性设置为 Sizable、FixedDialog、Fixed3D 等。其中之一必然会为您提供所需的行为。

      【讨论】:

      • 我不确定你是否理解这个问题。我只希望表单具有像第一张图像一样的细边框,并且能够移动表单而不会变大。 FormBorderStyle 都不符合我的需要。
      • FixedDialog 是您唯一的选择。除非您想承担相当大的工作来编写自己的 WInForms 容器!?
      • 有什么办法可以隐藏关闭按钮吗?我也找到了这个.. customerborderform.codeplex.com 但不知道你是否可以隐藏按钮。必须看看。
      • 酷。您无法隐藏它,但您可以使用 codeproject.com/Articles/20379/Disabling-Close-Button-on-Forms 禁用它。
      • 其实,检查这个答案stackoverflow.com/a/7301913/626442你可以把它连同最小和最大按钮一起删除...
      猜你喜欢
      • 1970-01-01
      • 2020-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-31
      相关资源
      最近更新 更多