当前位置:主页>delphi技巧/代码下载> 文章内容

我怎么把我求出来的和 返回到 edit.text 里面去

发布时间:2010-04-30 | QQ免费站
1楼: 在窗体上画一个球,(能画立体的球吗?不能画圆圈也行了),让他在窗体内随机运动,到达窗体的边界时就跟光线的镜面反射似的,弹到另一边,在碰到界面,在弹出,就这样在窗体内作无规则运动,怎么实现?代码详细点好吗?谢谢大虾们啦!
字串6

2楼: var MainRect : TRect; curPos : TPoint; offsetX, offsetY:Integer; ptocedure Timer1OnTimer(Sender: TObject) begin Inc(curPos.cx, offsetX); Inc(curPos.cy, offsetY); if (offsetX<0) and (curPos.cx<0) then begin offsetX:= offsetX * -1; curPos.cx:=curPos.cx * -1; end; if (offsetX>0) and (curPos.cx>=MainRect.Width) then begin offsetX:= offsetX * -1; curPos.cx:=2*MainRect.Width - curPos.cx; end; if (offsetY<0) and (curPos.cy<=0) then begin offsetY:= offsetY * -1; curPos.cy:=curPos.cy * -1; end; if (offsetY>0) and (curPos.cy>=MainRect.Bottom) then begin offsetX:= offset * -1; curPos.cx:=MainRect.Bottom * 2 - curPos.cy; end; end; 字串7

3楼: program Bounce; uses Windows, Messages, Math; // 窗体消息处理函数 function WndProc(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; const ID_TIMER = 1; // 定时器ID {$J+} hBitmap: Integer = 0; // 位图句柄 cxClient: Integer = 0; cyClient: Integer = 0; xCenter: Integer = 0; yCenter: Integer = 0; cxTotal: Integer = 0; cyTotal: Integer = 0; cxRadius: Integer = 0; cyRadius: Integer = 0; cxMove: Integer = 0; cyMove: Integer = 0; xPixel: Integer = 0; yPixel: Integer = 0; {$J-} var hBrush: LongWord; // 画刷句柄 hdcWnd, hdcMem: HDC; iScale: Integer; begin Result := 0; case Msg of WM_CREATE: begin hdcWnd := GetDC(hWnd); xPixel := GetDeviceCaps(hdcWnd, ASPECTX); yPixel := GetDeviceCaps(hdcWnd, ASPECTY); ReleaseDC(hWnd, hdcWnd); SetTimer(hWnd, ID_TIMER, 50, nil); end; WM_SIZE: begin cxClient := LOWORD(lParam); cyClient := HIWORD(lParam); xCenter := cxClient div 2; yCenter := cyClient div 2; iScale := Min(cxClient * xPixel, cyClient * yPixel) div 16; cxRadius := iScale div xPixel; cyRadius := iScale div yPixel; cxMove := Max(1, cxRadius div 2); cyMove := Max(1, cyRadius div 2); cxTotal := 2 * (cxRadius + cxMove); cyTotal := 2 * (cyRadius + cyMove); if (hBitmap <> 0) then DeleteObject(hBitmap); hdcWnd := GetDC(hWnd); hdcMem := CreateCompatibleDC(hdcWnd); hBitmap := CreateCompatibleBitmap(hdcWnd, cxTotal, cyTotal); ReleaseDC(hWnd, hdcWnd); SelectObject(hdcMem, hBitmap); Rectangle(hdcMem, -1, -1, cxTotal + 1, cyTotal + 1); hBrush := CreateHatchBrush(HS_DIAGCROSS, 0); SelectObject(hdcMem, hBrush); SetBkColor(hdcMem, RGB(255, 0, 255)); Ellipse(hdcMem, cxMove, cyMove, cxTotal - cxMove, cyTotal - cyMove); DeleteDC(hdcMem); DeleteObject(hBrush); end; WM_TIMER: begin if (hBitmap = 0) then Exit; hdcWnd := GetDC(hWnd); hdcMem := CreateCompatibleDC(hdcWnd); SelectObject(hdcMem, hBitmap); BitBlt(hdcWnd, xCenter - cxTotal div 2, yCenter - cyTotal div 2, cxTotal, cyTotal, hdcMem, 0, 0, SRCCOPY); ReleaseDC(hWnd, hdcWnd); DeleteDC(hdcMem); Inc(xCenter, cxMove); Inc(yCenter, cyMove); if (xCenter + cxRadius >= cxClient) or (xCenter - cxRadius <= 0) then cxMove := -cxMove; if (yCenter + cyRadius >= cyClient) or (yCenter - cyRadius <= 0) then cyMove := -cyMove; end; WM_DESTROY: begin if (hBitmap <> 0) then DeleteObject(hBitmap); KillTimer(hWnd, ID_TIMER); PostQuitMessage(0); // 退出 end; else Result := DefWindowProc(hWnd, Msg, wParam, lParam); // 标准处理 end; end; const szAppName = ‘Bounce‘; var hWnd: LongWord; Msg: TMsg; WndClass: TWndClass; begin // 注册窗体类 WndClass.style := CS_HREDRAW or CS_VREDRAW; WndClass.lpfnWndProc := @WndProc; WndClass.cbClsExtra := 0; WndClass.cbWndExtra := 0; WndClass.hInstance := hInstance; WndClass.hIcon := LoadIcon(0, IDI_APPLICATION); WndClass.hCursor := LoadCursor(0, IDC_ARROW); WndClass.hbrBackground := GetStockObject(WHITE_BRUSH); WndClass.lpszMenuName := nil; WndClass.lpszClassName := szAppName; if (RegisterClass(WndClass) = 0) then begin MessageBox(0, ‘This program requires Windows NT!‘, szAppName, MB_ICONERROR); Exit; end; // 建立窗体 hWnd := CreateWindow(szAppName, ‘Bouncing Ball‘, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, hInstance, nil); // 显示窗体 ShowWindow(hWnd, CmdShow); UpdateWindow(hWnd); // 消息循环 while GetMessage(Msg, 0, 0, 0) do begin TranslateMessage(Msg); DispatchMessage(Msg); end; end.

字串8

4楼: 使用一個timer組件加一個image組件 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, jpeg, ExtCtrls; type TForm1 = class(TForm) Timer1: TTimer; Image1: TImage; BitBtn1: TBitBtn; procedure Timer1Timer(Sender: TObject); procedure FormCreate(Sender: TObject); procedure BitBtn1Click(Sender: TObject); private top:boolean; left:boolean; { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Timer1Timer(Sender: TObject); begin if top then image1.Top:=image1.Top-10 else image1.Top:=image1.Top+10; if (image1.top<0) or (image1.top>=(form1.Height-image1.Height-40)) then top:=not top; if left then image1.Left:=image1.Left-10 else image1.Left:=image1.Left+10; if (image1.left<0) or (image1.left>(form1.Width-image1.Width-20)) then left:=not left; end; procedure TForm1.FormCreate(Sender: TObject); begin top:=true; left:=true; end; procedure TForm1.BitBtn1Click(Sender: TObject); begin timer1.Enabled :=not timer1.Enabled; end; end. 這個剛剛調試通過.. 字串7

5楼: //以下代码是一个图片,当然你可以设置成圆形的;这个图片在窗体的范围左右移动,你可以稍做修改,把它任意移动; unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls, StdCtrls, Spin, ExtCtrls, ImgList; type //声明线程 TAnimThread=class(TThread) private B:TBitmap; procedure DrawAnimpic; protected procedure Execute;override; end; type TAW = class(TForm) Label1: TLabel; Label2: TLabel; Button1: TButton; StatusBar1: TStatusBar; ImageList1: TImageList; SpinEdit1: TSpinEdit; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure SpinEdit1Change(Sender: TObject); procedure FormDestroy(Sender: TObject); private AnimThread:TAnimThread; { Private declarations } public { Public declarations } end; var AW:TAW; run:Boolean; implementation {$R *.dfm} procedure TAnimThread.DrawAnimpic; begin AW.Canvas.CopyRect(Bounds(0,0,AW.Width,50),b.Canvas,Bounds(0,0,AW.Width,50)); BitBlt(AW.Canvas.Handle,0,0,AW.Width,50,b.Canvas.Handle,0,0,srccopy); //BitBlt(AW.Canvas.Handle,50,50,50,50,b.Canvas.Handle,50,50,srccopy); end; procedure TAnimThread.Execute; var x,i:integer; Dir:Boolean; begin b:=TBitmap.Create; b.Width:=AW.Width; b.Height:=50; b.Canvas.Pen.Color:=clPurple; b.Canvas.Brush.Color:=clSkyBlue; b.Canvas.Rectangle(0,0,AW.Width,50); dir:=false; //定义方向 x:=0; i:=0; repeat begin inc(i); b.Canvas.Rectangle(0,0,AW.Width,50); //AW.ImageList1.Draw(30,30,b); AW.ImageList1.Draw(b.Canvas,x,15,i); //绘制imagelist中的第i+1幅图片 Synchronize(DrawAnimpic); //同步 Sleep(Aw.SpinEdit1.Value); //延迟时间 if (x=0) or (x=AW.Width) then dir:=not dir; //反向移动 if dir then inc(x) else Dec(x); //左右移动图片 if i>=AW.ImageList1.Count-1 then i:=0; end; until Terminated; b.Free; end; procedure TAW.Button1Click(Sender: TObject); begin run:=not run; if run then AnimThread:=TAnimThread.Create(false) else AnimThread.Free; if Button1.Caption=‘开始‘ then Button1.Caption:=‘结束‘ else button1.Caption:=‘开始‘; //end; end; procedure TAW.FormCreate(Sender: TObject); begin run:=false; end; procedure TAW.SpinEdit1Change(Sender: TObject); begin if SpinEdit1.Value<10 then begin Button1Click(self); showmessage(‘设置的数值太小,可能影响运行效果!‘); end; end; procedure TAW.FormDestroy(Sender: TObject); begin if not AnimThread.Terminated then begin AnimThread.Free; //窗体关闭时,释放对象 end; end; end. 字串3

6楼: 一帮大傻
字串7

7楼: 谢谢各位啦,王东迪这傻帽咋来了?

字串1