如何让窗体显示

xiaoxin4321 2009-11-15 09:28:18
我想实现一个拖到窗口上方自动隐藏,和鼠标放上去自动显示的功能
是这样的,我在mousemove 里判断

if( Top ==0)
this.Top = this.Top - this.Height + 5;

让他缩到上方,这样的话,如何才能够让他再次显示出来啊
我在mouseenter里

if (this.Top < 0)
{

ResizeToOrginal(); //还原成初始大小
}

这样就会出现死循环。。。请大家提点一下~

嘿嘿,还有怎么把贴出来的代码像其他人那样比较整齐的,带有c# code这样的?
...全文
224 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoxin4321 2009-11-16
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 wartim 的回复:]
C# codeusing 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 WindowsFormsApplication2
{publicpartialclass Form1 : Form
{int OrgHeight=0;
Timer T=new Timer();public Form1()
{
InitializeComponent();

OrgHeight=this.Height;this.LocationChanged+=new EventHandler(Form1_LocationChanged);this.MouseEnter+=new EventHandler(Form1_MouseEnter);
T.Interval=100;
T.Tick+=new EventHandler(T_Tick);
}void T_Tick(object sender, EventArgs e)
{if (!this.Bounds.Contains(Control.MousePosition)&&this.Top==0)
{
HideForm();
T.Enabled=false;
}
}void Form1_MouseEnter(object sender, EventArgs e)
{if (this.FormBorderStyle== FormBorderStyle.None)
{this.FormBorderStyle= FormBorderStyle.Sizable;this.Height= OrgHeight;
T.Enabled=true;
}
}void Form1_LocationChanged(object sender, EventArgs e)
{if (this.Top<=0)
{
HideForm();
T.Enabled=false;
}
}privatevoid HideForm()
{this.Top=0;this.FormBorderStyle= FormBorderStyle.None;this.Height=1;
}
}
}
[/Quote]

谢谢这位,呵呵~
xiaoxin4321 2009-11-15
  • 打赏
  • 举报
回复
有个问题,
  this.Top = this.Top - this.Height + 5; 

这样设置的话,窗体居然完全消失了,没辙~
huangyuelei01 2009-11-15
  • 打赏
  • 举报
回复
eaglegrace 2009-11-15
  • 打赏
  • 举报
回复
通过鼠标拖动窗口到最上方来隐藏窗口,好像还有点问题。不是每次都能隐藏
wuyq11 2009-11-15
  • 打赏
  • 举报
回复
主要是判断top位置,定时查询鼠标位置实现显示
staticuser 2009-11-15
  • 打赏
  • 举报
回复
呵呵,我帮你顶下哦
xiaoxin4321 2009-11-15
  • 打赏
  • 举报
回复
 原来是这样的
kafanqd 2009-11-15
  • 打赏
  • 举报
回复
学习!
qlg270 2009-11-15
  • 打赏
  • 举报
回复
不错 学习啦
z415353144 2009-11-15
  • 打赏
  • 举报
回复
up
wartim 2009-11-15
  • 打赏
  • 举报
回复
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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
int OrgHeight = 0;
Timer T = new Timer();

public Form1()
{
InitializeComponent();

OrgHeight = this.Height;
this.LocationChanged += new EventHandler(Form1_LocationChanged);
this.MouseEnter += new EventHandler(Form1_MouseEnter);
T.Interval = 100;
T.Tick += new EventHandler(T_Tick);
}

void T_Tick(object sender, EventArgs e)
{
if (!this.Bounds.Contains(Control.MousePosition) && this.Top == 0)
{
HideForm();
T.Enabled = false;
}
}

void Form1_MouseEnter(object sender, EventArgs e)
{
if (this.FormBorderStyle == FormBorderStyle.None)
{
this.FormBorderStyle = FormBorderStyle.Sizable;
this.Height = OrgHeight;
T.Enabled = true;
}
}

void Form1_LocationChanged(object sender, EventArgs e)
{
if (this.Top <= 0)
{
HideForm();
T.Enabled = false;
}
}

private void HideForm()
{
this.Top = 0;
this.FormBorderStyle = FormBorderStyle.None;
this.Height = 1;
}
}
}
Comforter 2009-11-15
  • 打赏
  • 举报
回复
改变可见性行么
hario 2009-11-15
  • 打赏
  • 举报
回复
标记。。。。。
看看后面的回答。。。
z415353144 2009-11-15
  • 打赏
  • 举报
回复
好问题。思考。。。。
xiaoxin4321 2009-11-15
  • 打赏
  • 举报
回复
再看看~
liherun 2009-11-15
  • 打赏
  • 举报
回复
每天回贴可获得10可用分
xiaoxin4321 2009-11-15
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 sosoyiyi 的回复:]
引用 5 楼 xiaoxin4321 的回复:
有个问题,
this.Top=this.Top-this.Height+5;
这样设置的话,窗体居然完全消失了,没辙~

你用top-height是 <0的,如果height再大点,+5也 <0,也就是说这条语句执行之后form的top值小于0,都不晓得显示到哪里去咯。。。
[/Quote]
其实我这里的top就是0左右的数值了~
happy664618843 2009-11-15
  • 打赏
  • 举报
回复
友情帮顶
bighero4 2009-11-15
  • 打赏
  • 举报
回复
不是设置this.top的值,而应该设置this.height的值,但不能像楼上说的,设为0,如果设为0,那么收起来后恐怕就感应不到mouseenter了,可以设置成一个>0的比较小的值,如:5应该可以的。
sosoyiyi 2009-11-15
  • 打赏
  • 举报
回复
其实,当你拖动窗体的时候,可以判断窗体当前的位置,当top值<=0的时候,就不能再拖动了,然后把height的值设为0就行了
加载更多回复(1)

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧