首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

有关问题

2011-12-24 
问题窗口在RESIZE时是显示一个虚拟框架怎么在程序中显示这样的?比如用户点了一个BUTTON然后开始移动我想显

问题
窗口在RESIZE时   是显示一个虚拟框架  
怎么在程序中显示这样的?

比如用户点了一个BUTTON   然后开始移动   我想显示一个BUTTON的虚影

但是仍然可以看到背景


[解决办法]
up
[解决办法]
Draw吧
[解决办法]
帮LZ顶
[解决办法]
gdi+
[解决办法]
没搞过,up
[解决办法]

[解决办法]
gdi+

先把这个button抓下来,在屏幕上显示
[解决办法]
嘿,有意思..
mark.
[解决办法]
budong
[解决办法]
这个是系统社定,可以在控制面板里面改,忘记具体叫什么属性了
改了后所有窗体都可以这么移动
[解决办法]
而且你看例如QQ的窗体也是这么移动的
[解决办法]
根据鼠标移动,自己画一个`~```
[解决办法]
不会,学习
[解决办法]
非要做的话就要用GDI+自己画了,不过比较麻烦,需要在不断画新的线的同时“擦除”原有的线
[解决办法]
帮接分
[解决办法]
看看个吧
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace BaseControls
{
/// <summary>
/// splitbar 的摘要说明:用于界面的控件分割条作用。
///Author:XC
///Date:2005-03-18
///使用方法:先在使用的窗口放该控件,然后在属性中的杂项中选择dragtype确定左右拖拽还是上下拖拽,
///在窗体的初始化中调用:该控件的init()和RegControl注册要拖拽的控件
/// </summary>
public class Splitbar : System.Windows.Forms.UserControl
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Splitbar()
{ // 该调用是 Windows.Forms 窗体设计器所必需的。
InitializeComponent();

// TOD 在 InitializeComponent 调用后添加任何初始化

}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>

protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
} base.Dispose( disposing );
}

#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>

private void InitializeComponent()
{
//
// Splitbar
//
this.BackColor = System.Drawing.SystemColors.ControlDark;
this.Cursor = System.Windows.Forms.Cursors.VSplit;
this.Name = "Splitbar "; this.Size = new System.Drawing.Size(24, 162);
this.Click += new System.EventHandler(this.Splitbar_Click);
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.splitbar_MouseUp);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.splitbar_MouseMove);


this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.splitbar_MouseDown);

}
#endregion

public enum drag
{
updown = 0,
leftright
}

bool dragbegin;
public Color dragcolor = Color.FromArgb(133,133,133);
private int oldx, oldy, startx, starty;
public int minlt = 30,minrb = 30;
drag dragtype = drag.leftright;

/// <summary>
/// 设置被分割控件(左边或上边)的最小尺
/// </summary>

public int MinLT
{
get
{
return minlt;
} set
{
if (value < 0)
{
throw new ArgumentOutOfRangeException( "MinLT ", value, "MinLT 设置被分割控件(左边或上边)的最小尺寸,该值应该大于等于0! ");
}
else
{
minlt = value;
}
}
}

/// <summary>
/// 设置被分割控件(右边或下边)的最小尺
/// </summary>

public int MinRB
{
get
{
return minrb;
}
set
{
if (value < 0)
{
throw new ArgumentOutOfRangeException( "MinRB ", value, "MinRB 设置被分割控件(左边或上边)的最小尺寸,该值应该大于等于0! ");
}
else
{
minrb = value;
}
}
}

/// <summary>
/// 拖拽时显示的颜色
/// </summary>

public Color DragColor
{
get
{
return dragcolor;
}
set
{
dragcolor = value;
}
}
/// <summary>
/// 分割方式,updown:上下分割, leftright:左右分割。
/// </summary>

public drag DragType
{
get
{
return dragtype;
}
set
{
dragtype = value;
}
}

ArrayList ArrayLT = new ArrayList(); ArrayList ArrayRB = new ArrayList();

/// <summary>
///注册被分割的控件,type代表注册拖拽的两边
/// </summary>
/// <param name= "lr "> </param>
/// <param name= "ctrl "> </param>
/// <returns> </returns>

public int RegControl(int type, Control ctrl)
{
this.BackColor = this.Parent.BackColor;
switch (type)
{
case 0://左或上
ArrayLT.Add(ctrl);
break;
case 1://右或下
ArrayRB.Add(ctrl);
break;
}
return 1;
}

private void splitbar_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
int mousex,mousey, movex,movey; Point point;
point = this.Parent.PointToClient(MousePosition);
mousex = point.X; mousey = point.Y;
movex = Math.Abs(mousex - startx);
movey = Math.Abs(mousey - starty);
Location.Offset(mousex,mousey);
if (e.Button == MouseButtons.Left)
{ this.Capture=true;
dragbegin = true;
if (dragtype == 0)
{
if (mousey > oldy)
{
foreach(Control control in ArrayRB)
{
if ( control.Size.Height - movey < minrb)
{
return;
}
}
}
else if (mousey < oldy)
{
foreach(Control control in ArrayLT)
{
if (control.Size.Height - movey < minlt)
{
return;
}
}
}
this.Location = new Point(this.Location.X, mousey);
}
else
{


if (mousex > oldx)
{
foreach ( Control control in ArrayRB)
{
if (control.Size.Width - movex < minrb)
{
return;
}
}
}
else if (mousex < oldx)
{
foreach(Control control in ArrayLT)
{
if (control.Size.Width - movex < minlt)
{
return;
}
}
}
this.Location = new Point(mousex,this.Location.Y);
}
oldx = mousex;
oldy = mousey;
this.BringToFront();
}
}

private void splitbar_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
oldx = this.Location.X;
oldy = this.Location.Y;
startx = oldx;
starty = oldy;
this.BackColor = DragColor ;

}
}

private void splitbar_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Left & dragbegin)
{
dragbegin = false;
this.BackColor = Parent.BackColor;
if (oldx != Location.X | oldy != Location.Y)
{
AdjustPosition();
}
}
}

/// <summary>
/// 调整注册的分割控件的位置大小
/// </summary>

public void AdjustPosition()
{
int movex, movey;
movex = (Location.X - startx);
movey = (Location.Y - starty);
switch (dragtype)
{
case drag.updown:
foreach(Control control in ArrayLT)
{
control.Size = new Size(control.Size.Width,control.Size.Height + movey );
}
foreach(Control control in ArrayRB)
{
control.Location = new Point (control.Location.X,control.Location.Y + movey );
control.Size = new Size(control.Size.Width,control.Size.Height - movey);
}
break;
case drag.leftright:
foreach(Control control in ArrayLT)
{
control.Size = new Size(control.Size.Width + movex, control.Size.Height);
}

foreach(Control control in ArrayRB)
{
control.Location = new Point((control.Location.X + movex),control.Location.Y);
control.Size = new Size((control.Size.Width - movex),control.Size.Height);
}
break;
}
}

public void Init()
{
BackColor = Parent.BackColor;
}

private void Splitbar_Click(object sender, System.EventArgs e)
{
this.BackColor = Parent.BackColor;
}
}
}

热点排行