A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 丁艳姣 中级黑马   /  2012-10-25 13:37  /  2163 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

当把winform的formborderstyle属性设置为none时,即为无边框窗体,那么任务栏上的图标的左键和右键功能就没有反应了,请问该怎样解决啊?

评分

参与人数 1技术分 +1 收起 理由
王松老师 + 1

查看全部评分

1 个回复

倒序浏览
1、在Class里面加入

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication1
...{
    class Class1
    ...{
        System.Windows.Forms.Form FormA;

        public void Skin(System.Windows.Forms.Form frm)
        ...{
            FormA = frm;

            frm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            frm.BackColor = System.Drawing.SystemColors.Desktop;
            frm.TransparencyKey = System.Drawing.SystemColors.Desktop;

            NoneBorder();
        }

        // http://blog.csdn.net/hbxtlhx/archive/2007/08/01/1721061.aspx
        [DllImport("user32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)]
        public static extern int GetWindowLong(HandleRef hWnd, int nIndex);

        [DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)]
        public static extern IntPtr SetWindowLong(HandleRef hWnd, int nIndex, int dwNewLong);
      
        void NoneBorder()
        ...{
            int WS_SYSMENU = 0x00080000; // 系统菜单
            int WS_MINIMIZEBOX = 0x20000; // 最大最小化按钮

            int windowLong = (GetWindowLong(new HandleRef(FormA, FormA.Handle), -16));
            SetWindowLong(new HandleRef(FormA, FormA.Handle), -16, windowLong | WS_SYSMENU | WS_MINIMIZEBOX);
        }
    }
}

2、在Form中调用

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
...{
    public partial class Form1 : Form
    ...{
        Class1 SkinClass = new Class1();

        public Form1()
        ...{
            InitializeComponent();

            SkinClass.Skin(this);
        }
    }
}
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马