社区
C++ Builder
帖子详情
如何实现控件的拉伸?
yyuc20000
2006-10-18 12:33:37
例如动态生成一个Edit控件,我怎样才能实现它的各个方向的拉伸呢?
...全文
241
7
打赏
收藏
如何实现控件的拉伸?
例如动态生成一个Edit控件,我怎样才能实现它的各个方向的拉伸呢?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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。
可拖动
拉伸
任意排版
控件
模仿MFC资源编辑界面,可
实现
控件
任意拖动,
拉伸
,左右上下对齐,
实现
打印排版并将坐标保存为xml
WPF
实现
控件
的移动、旋转、
拉伸
的Demo
WPF
实现
控件
的移动 拖放 旋转功能。
实现
了
控件
的自定义旋转、
拉伸
旋转功能
实现
的文档介绍见博客园 一个小Demo主要是配合文档使用的 但不知道博客园中如何传代码 就穿到这了 若觉得对您有帮助可以下下来看看。
VLC.dotNet播放器-回调方式支持
拉伸
充满
控件
-兼容32位和64位.rar
基于VLC.dotNet.core编写的VLC播放器。 基本功能:播放、暂停、停止、快进、快退、按真实宽高比播放 特殊功能:支持
拉伸
充满
控件
、支持叠加LOGO、支持叠加透明图片(例如:箭头)
实现
方式:通过lock回调、unlock回调、display回调,将解码后的视频显示到
控件
区域,支持
拉伸
模式和真实宽高比模式。(解码回调与libvlc基本一致) 视频长度、进度的判断,都在回调中
实现
,不需要使用定时器。 本源码从省级视频监控平台中抽取,经过大量测试,功能正确、稳定可靠。 欢迎参考利用。
C# wpf 附加属性
实现
任意
控件
拖动调整大小
使用附加属性将各种
控件
拖动改变大小功能整合到一起,提高复用性和移植性,界面和逻辑分离,支持自定义拖动样式。原文链接:https://blog.csdn.net/u013113678/article/details/121719278
C# 自定义
控件
实现
可伸缩的Panel
控件
在C#中,
实现
可以自由扩展缩进的Panel自定义
控件
,并支持多个Panel自定义
控件
间的联动伸缩。
C++ Builder
13,825
社区成员
102,679
社区内容
发帖
与我相关
我的任务
C++ Builder
C++ Builder相关内容讨论区
复制链接
扫一扫
分享
社区描述
C++ Builder相关内容讨论区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章