我在button 中click事件
            formonpaint中写
canvas.Brush.Color:=clred;
canvas.Brush.Style:=bssolid;
canvas.FillRect(rect(80,550,140,500));  是有效的但在formshow,formcreate中同样的语句是无效的,请教为何???

解决方案 »

  1.   

    自己調試一下﹐看看formshow,formcreate﹐formonpaint的先后順序就知道是怎么回事了?
      

  2.   

    不知道我说的对不对请各位指正以 create 为例constructor TCustomForm.Create(AOwner: TComponent);
    begin
      GlobalNameSpace.BeginWrite;
      try
        CreateNew(AOwner);              //会在这调用CreateNew
        if (ClassType <> TForm) and not (csDesigning in ComponentState) then
        begin
          Include(FFormState, fsCreating);
          try
            if not InitInheritedComponent(Self, TForm) then
              raise EResNotFound.CreateFmt(SResNotFound, [ClassName]);
          finally
            Exclude(FFormState, fsCreating);
          end;
          if OldCreateOrder then DoCreate;
        end;
      finally
        GlobalNameSpace.EndWrite;
      end;
    end;
    constructor TCustomForm.CreateNew(AOwner: TComponent; Dummy: Integer);
    begin
      inherited Create(AOwner);
      ControlStyle := [csAcceptsControls, csCaptureMouse, csClickEvents,
        csSetCaption, csDoubleClicks];
      Left := 0;
      Top := 0;
      Width := 320;
      Height := 240;
      FIcon := TIcon.Create;
      FIcon.Width := GetSystemMetrics(SM_CXSMICON);
      FIcon.Height := GetSystemMetrics(SM_CYSMICON);
      FIcon.OnChange := IconChanged;
      FCanvas := TControlCanvas.Create; //会在这儿新建一个FCanvas。      
                                        //所以就相当于重画了一遍
      FCanvas.Control := Self;
      FBorderIcons := [biSystemMenu, biMinimize, biMaximize];
      FBorderStyle := bsSizeable;
      FWindowState := wsNormal;
      FDefaultMonitor := dmActiveForm;
      FInCMParentBiDiModeChanged := False;
      FPixelsPerInch := Screen.PixelsPerInch;
      FPrintScale := poProportional;
      FloatingDockSiteClass := TWinControlClass(ClassType);
      FAlphaBlendValue := 255;
      FTransparentColorValue := 0;
      Visible := False;
      ParentColor := False;
      ParentFont := False;
      Ctl3D := True;
      Screen.AddForm(Self);
    end;
    最近刚开始看delphi的内部源码,许多东西还不懂,请大家用鸡蛋扔我,不用客气哈,不要因为我长的帅,人缘好就手下留情,哈哈
      

  3.   

    老大,你应该买一本Windows程序设计看看,里面讲的非常清楚了,Windows的窗口程序在建立到显示出来,调用的各个API的顺序,和整个程序的执行流程,那本书也讲的非常清楚了,不过那本书中文版据说翻译的很烂(没有看过简体中文的,我不知道是否是很烂),但是价格绝对是恐怖的。160大洋
      

  4.   

    楼上的Windows程序设计
    好像有电子版的等俺去找找
      

  5.   

    窗体产生时的事件次序
    action eventcreate oncreateshow onshow  paint onpaintactivate onactivate  resize onresize  paint onpaintclose query onclosequeryclose onclosedeactivate ondeactivatehide onhidedestroy ondestr转贴