C#无边框窗体实现以及拖动代码
程序员文章站
2023-12-19 08:10:22
实现效果:
代码:
using system;
using system.collections.generic;
using system.compo...
实现效果:
代码:
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; namespace noborderform { public partial class form1 : form { public form1() { initializecomponent(); } private void form1_load(object sender, eventargs e) { } point mouseoff;//鼠标移动位置变量 bool leftflag;//标记是否为左键 private void form1_mousedown(object sender, mouseeventargs e) { if (e.button == mousebuttons.left) { mouseoff = new point(-e.x, -e.y); //得到变量的值 leftflag = true; //点击左键按下时标注为true; } } private void form1_mousemove(object sender, mouseeventargs e) { if (leftflag) { point mouseset = control.mouseposition; mouseset.offset(mouseoff.x, mouseoff.y); //设置移动后的位置 location = mouseset; } } private void form1_mouseup(object sender, mouseeventargs e) { if (leftflag) { leftflag = false;//释放鼠标后标注为false; } } private void button1_click(object sender, eventargs e) { dialogresult dr = messagebox.show("yes/no", "exit", messageboxbuttons.yesno, messageboxicon.warning); if (dr == dialogresult.yes) { this.close(); } else { return; } } private void button2_click(object sender, eventargs e) { this.windowstate = formwindowstate.minimized; } private void checkbox1_checkedchanged(object sender, eventargs e) { } private void form1_click(object sender, eventargs e) { } private void panel1_click(object sender, eventargs e) { } private void textbox1_click(object sender, eventargs e) { } private void linklabel1_linkclicked(object sender, linklabellinkclickedeventargs e) { system.diagnostics.process.start("http://www.baidu.com"); } private void button4_click(object sender, eventargs e) { } } }