社区
C++ Builder
帖子详情
如何实现控件的拉伸?
yyuc20000
2006-10-18 12:33:37
例如动态生成一个Edit控件,我怎样才能实现它的各个方向的拉伸呢?
...全文
246
7
打赏
收藏
如何实现控件的拉伸?
例如动态生成一个Edit控件,我怎样才能实现它的各个方向的拉伸呢?
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
7 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
truelove7283159
2006-10-31
打赏
举报
回复
上面那些方法调来调去都要调到resize()VCL就是这样干的。
truelove7283159
2006-10-31
打赏
举报
回复
在控件的resize方法中处理。
i_love_pc
2006-10-31
打赏
举报
回复
学习.
yyuc20000
2006-10-30
打赏
举报
回复
好,我试试。谢谢。
jiangshx
2006-10-18
打赏
举报
回复
////////////////////////////.h文件
class TForm1 : public TForm
{
__published:// IDE-managed Components
TButton *Button2;
TButton *Button1;
void __fastcall ControlMouseMove(TObject *Sender, TShiftState Shift,
int X, int Y);
void __fastcall ControlMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
void __fastcall ControlMouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
private:// User declarations
int Type;
enum rectINFO{
RIGHT=1,
LEFT=2,
BOTTOM=4,
TOP=8,
};
TPoint Pos0;
TCursor __fastcall GetCursor(int X, int Y, TObject *Sender);
public:// User declarations
__fastcall TForm1(TComponent* Owner);
};
////////////////////////////.cpp文件
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
TButton *newbtn=new TButton(this);
newbtn->Parent=Form1;
newbtn->Left=100;
newbtn->Top=100;
newbtn->Height=25;
newbtn->Width=60;
newbtn->Caption="新的按钮";
newbtn->OnMouseUp=ControlMouseUp;
newbtn->OnMouseDown=ControlMouseDown;
newbtn->OnMouseMove=ControlMouseMove;
}
//-------------------------------------------------------------
TCursor __fastcall TForm1::GetCursor(int X, int Y, TObject *Sender)
{
TControl* Control;
Type = 0;
Control = dynamic_cast<
TControl*>(Sender);
if (Control == NULL)
return crDefault;
if (Control->ClientWidth-X<=4)
Type |= RIGHT;
else if(X <= 4)
Type |= LEFT;
if (Control->ClientHeight-Y<=4)
Type |= BOTTOM;
else if(Y <= 4)
Type |= TOP;
if (Type==LEFT || Type==
RIGHT)
return crSizeWE;
if (Type==TOP || Type==
BOTTOM)
return crSizeNS;
if (Type==(LEFT|TOP) ||
Type==(RIGHT|BOTTOM))
return crSizeNWSE;
if (Type==(LEFT|BOTTOM)
|| Type==(RIGHT|TOP))
return crSizeNESW;
return crDefault;
}
//------------------------------------------------------------
void __fastcall TForm1::ControlMouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
int dx, dy;
TRect Rect;
TPoint Pos;
TWinControl* Control;
Control = dynamic_cast<
TWinControl*>(Sender);
if (Control==NULL) return;
if (Mouse->Capture==Control->Handle) {
Pos.x = X; Pos.y = Y;
::ClientToScreen(Control
->Handle, &Pos);
dx = Pos.x - Pos0.x;
dy = Pos.y - Pos0.y;
GetWindowRect(Control->
Handle, &Rect);
if (Type & LEFT)
Rect.left += dx;
else if(Type & RIGHT)
Rect.right += dx;
if (Type & TOP)
Rect.top += dy;
else if(Type & BOTTOM)
Rect.bottom += dy;
MapWindowPoints(0, Handle,
(POINT*)&Rect, 2);
MoveWindow(Control->Handle,
Rect.left, Rect.top, Rect
.Width(), Rect.Height(),
TRUE);
UpdateWindow(Control->Handle);
Pos0.x = Pos.x; Pos0.y = Pos.y;
}
else {
TCursor cursor = GetCursor(X, Y,
Sender);
if (cursor != Control->Cursor) {
Control->Cursor = cursor;
::SetCursor(Screen->Cursors[
cursor]);
}
}
}
//--------------------------------------------------------
void __fastcall TForm1::ControlMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
TWinControl* Control;
Control = dynamic_cast<
TWinControl*>(Sender);
if (Type==0){
if(Button == mbLeft){//如果是左键按下控件,则可以移动控件
ReleaseCapture();
SendMessage( Control->Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
}
return;
}
if (Type!=0 && Control!=0) {
Pos0.x = X; Pos0.y = Y;
::ClientToScreen(Control->
Handle, &Pos0);
Mouse->Capture = Control
->Handle;
}
}
//------------------------------------------------------
void __fastcall TForm1::ControlMouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
TWinControl* Control;
if (Type==0) return;
Control = dynamic_cast<
TWinControl*>(Sender);
if (Control!=NULL && Mouse->
Capture==Control->Handle)
Mouse->Capture = NULL;
}
BlueDeepOcean
2006-10-18
打赏
举报
回复
参考这个帖子吧,道理是一样的:
http://community.csdn.net/Expert/topic/4750/4750745.xml?temp=.1326563
BlueDeepOcean
2006-10-18
打赏
举报
回复
需要动态定义它的OnMouseDown,OnMouseMove和OnMouseUp事件。并在OnMouseMove中处理它的Width和Height的变化事件。利用POINT决定x和y。
控件
拉伸
小例子
在Windows Forms中,我们可以使用各种布局策略,如FlowLayoutPanel或TableLayoutPanel,来帮助
实现
控件
的
拉伸
。 2. **自动缩放属性**: -
控件
通常有AutoSizeMode和AutoSize属性。AutoSizeMode决定了
控件
拉伸
的...
WPF
实现
控件
的移动、旋转、
拉伸
的Demo
WPF
实现
控件
的移动 拖放 旋转功能。
实现
了
控件
的自定义旋转、
拉伸
旋转功能
实现
的文档介绍见博客园 一个小Demo主要是配合文档使用的 但不知道博客园中如何传代码 就穿到这了 若觉得对您有帮助可以下下来看看。
VLC.dotNet播放器-回调方式支持
拉伸
充满
控件
-兼容32位和64位.rar
实现
方式:通过lock回调、unlock回调、display回调,将解码后的视频显示到
控件
区域,支持
拉伸
模式和真实宽高比模式。(解码回调与libvlc基本一致) 视频长度、进度的判断,都在回调中
实现
,不需要使用定时器。 本...
VC 可
拉伸
的对话框(动态改变子
控件
大小)
本项目名为"VC 可
拉伸
的对话框(动态改变子
控件
大小)",其主要目标是创建一个对话框,当用户调整对话框大小时,子
控件
的尺寸和字体大小能够自动调整,以保持良好的视觉效果和用户体验。 首先,我们需要理解对话框...
C#
控件
拖动与
拉伸
在项目中引用dll文件即可,使用时,创建对象,调用ZoomEnter(Control control)这个方法即可
C++ Builder
13,871
社区成员
102,693
社区内容
发帖
与我相关
我的任务
C++ Builder
C++ Builder相关内容讨论区
复制链接
扫一扫
分享
社区描述
C++ Builder相关内容讨论区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章