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

关于画线消失的有关问题

2012-04-02 
关于画线消失的问题在窗体上自由画线后,每次只要一最小化窗口或者别的窗口挡着时在回到窗体上,画的线就都

关于画线消失的问题
在窗体上自由画线后,每次只要一最小化窗口或者别的窗口挡着时在回到窗体上,画的线就都没了,各位帮忙指教一下这是怎么回事?该怎么解决呢?

[解决办法]
应该写到onpaint事件中....,resize是不准确的,我有一个小demo,要的话可以发给你
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ToolWin, Menus, ImgList, StdCtrls, ExtCtrls, XPMan,
ColorGrd;

type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
MnLine: TMenuItem;
MnEllipse: TMenuItem;
MnRectangle: TMenuItem;
ImageList1: TImageList;
CoolBar1: TCoolBar;
TBarShape: TToolBar;
TbLine: TToolButton;
TbEllipse: TToolButton;
TbRectangle: TToolButton;
N3: TMenuItem;
MnToolBar: TMenuItem;
MnStatusBar: TMenuItem;
StatusBar1: TStatusBar;
H1: TMenuItem;
MnAbout: TMenuItem;
TbArrow: TToolButton;
MnArrow: TMenuItem;
N2: TMenuItem;
Button1: TButton;
ColorDialog1: TColorDialog;
TbArrow2: TToolButton;
MnArrow2: TMenuItem;
XPManifest1: TXPManifest;
TbEllipse2: TToolButton;
TbLine2: TToolButton;
TbRectangle2: TToolButton;
MnLine2: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
MnEllipse2: TMenuItem;
MnRectangle2: TMenuItem;
TBarColor: TToolBar;
ColorGrid1: TColorGrid;
TBarPen: TToolBar;
ComboBox1: TComboBox;
procedure ComboBox1Select(Sender: TObject);
procedure ColorGrid1Click(Sender: TObject);
procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure MnRectangle2Click(Sender: TObject);
procedure MnEllipse2Click(Sender: TObject);
procedure MnLine2Click(Sender: TObject);
procedure MnArrow2Click(Sender: TObject);
procedure TbArrow2Click(Sender: TObject);

procedure MnArrowClick(Sender: TObject);
procedure MnAboutClick(Sender: TObject);
procedure MnStatusBarClick(Sender: TObject);
procedure MnToolBarClick(Sender: TObject);
procedure MnRectangleClick(Sender: TObject);
procedure MnLineClick(Sender: TObject);
procedure MnEllipseClick(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;

TDrawType = (dtLine,dtLine2,dtEllipse,dtEllipse2,dtRectangle);

TDrawBase = class
public
ptStart,ptEnd: TPoint;
// pt: array[0..1024] of TPoint;
pt: array of TPoint;
procedure DrawSelf(); virtual;
constructor create(DCanvas: TCanvas);
private
FCanvas: TCanvas;
FCursor: TCursor;
FPen: TPen;
FBrush: TBrush;
// FDrawType: TDrawType;
end;

TDrawLine = class(TDrawBase)
public
procedure DrawSelf();override;
end;

TDrawLine2 = class(TDrawBase)
public
procedure DrawSelf();override;
end;

TDrawEllipse = class(TDrawBase)
public
procedure DrawSelf();override;
end;

TDrawEllipse2 = class(TDrawBase)
public
procedure DrawSelf();override;
end;

TDrawRectangle = class(TDrawBase)
procedure DrawSelf();override;


end;

var
Form1: TForm1;
FDrawType: TDrawType;
FPen: TPen;
FPenWidth: Integer =1;
FPenColor: TColor;
FBrush: TBrush;
FBrushColor: TColor;
FBrushStyle: TBrushStyle;
DrawBase1: TDrawBase;
DrawList1: TList;
pts,pte: TPoint;
ptDelete: TPoint;
list_i: Integer;

const
crARROWM = 15;
implementation

uses ABOUT;

{$R *.dfm}
{$R dres.res}
{ TDrawBase }

constructor TDrawBase.create(DCanvas: TCanvas);
begin
Self.FCanvas := DCanvas;
Self.FCursor := crCross;
// Self.FCanvas.Brush := Self.FBrush;
// Self.FCanvas.Pen := Self.FPen;
end;

procedure TDrawBase.DrawSelf;
begin
// Self.FCanvas.Brush := Self.FBrush;
// Self.FCanvas.Pen.Width := Self.FPen.Width ;
Self.FCanvas.Pen := Self.FPen ;
Self.FCanvas.Brush := Self.FBrush;
// Added by peng 2006-7-31 16:43:30
end;

热点排行