Results 1 to 7 of 7

Thread: [Forms] how to pick colors (TColorPicker)

  1. #1
    Join Date
    May 2007
    Location
    baltimore, md
    Posts
    836
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default [Forms] how to pick colors (TColorPicker)

    Since some people have been asking about this i made a tutorial. I am pretty sure this only works in Scar 3.10-3.11. For this tutorial I am assuming you have standard knowledge of how a form works.

    First start out with a simple form


    SCAR Code:
    program New;

    var
      // InitForm variables.
      frmDesign : TForm;
      Button1 : TButton;
      colors : TEdit;

    procedure InitForm;
    begin
      frmDesign := CreateForm;
      frmDesign.Position := poDesktopCenter;
      frmDesign.BorderStyle := bsSingle;
      frmDesign.Width := 300;
      frmDesign.Height := 173;
      frmDesign.Caption := 'frmDesign';
      frmDesign.Color := clBtnFace;
      frmDesign.Font.Color := clWindowText;
      frmDesign.Font.Height := -11;
      frmDesign.Font.Name := 'MS Sans Serif';
      frmDesign.Font.Style := [];
      frmDesign.PixelsPerInch := 96;
      Button1 := TButton.Create(frmDesign);
      Button1.Parent := frmDesign;
      Button1.Left := 20;
      Button1.Top := 70;
      Button1.Width := 75;
      Button1.Height := 25;
      Button1.Caption := 'Pick color';
      Button1.TabOrder := 8;
      colors := TEdit.Create(frmDesign);
      colors.Parent := frmDesign;
      colors.Left := 100;
      colors.Top := 73;
      colors.Width := 121;
      colors.Height := 21;
      colors.TabOrder := 9;
      colors.Text := 'color';
    end;

    procedure SafeInitForm;
    var
      V : TVariantArray;
    begin
      SetArrayLength(V, 0);
      ThreadSafeCall('InitForm', V);
    end;

    procedure ShowInitFormModal;
    begin
      frmDesign.ShowModal;
    end;

    procedure SafeShowInitFormModal;
    var
      V : TVariantArray;
    begin
      SetArrayLength(V, 0);
      ThreadSafeCall('ShowInitFormModal', V);
    end;

    procedure MainInitForm;
    begin
      try
        SafeInitForm;
        SafeShowInitFormModal;
      finally
        FreeForm(frmDesign);
      except
        WriteLn('An error seems to have occurred in: InitForm');
      end;
    end;

    begin
      ClearDebug;
      MainInitForm;
    end.

    Then we add a Tcolorpicker var at the top, and create the tcolorpicker in the initform procedure.

    SCAR Code:
    program New;

    var
      // InitForm variables.
      frmDesign : TForm;
      Button1 : TButton;
      colors : TEdit;
      colorpicker : TColorPicker;//Add this

    procedure InitForm;
    begin
      frmDesign := CreateForm;
      frmDesign.Position := poDesktopCenter;
      frmDesign.BorderStyle := bsSingle;
      frmDesign.Width := 300;
      frmDesign.Height := 173;
      frmDesign.Caption := 'frmDesign';
      frmDesign.Color := clBtnFace;
      frmDesign.Font.Color := clWindowText;
      frmDesign.Font.Height := -11;
      frmDesign.Font.Name := 'MS Sans Serif';
      frmDesign.Font.Style := [];
      frmDesign.PixelsPerInch := 96;
      Button1 := TButton.Create(frmDesign);
      Button1.Parent := frmDesign;
      Button1.Left := 20;
      Button1.Top := 70;
      Button1.Width := 75;
      Button1.Height := 25;
      Button1.Caption := 'Pick color';
      Button1.TabOrder := 8;
      colors := TEdit.Create(frmDesign);
      colors.Parent := frmDesign;
      colors.Left := 100;
      colors.Top := 73;
      colors.Width := 121;
      colors.Height := 21;
      colors.TabOrder := 9;
      colors.Text := 'color';
      colorpicker := Tcolorpicker.Create(frmdesign);//add this too
    end;

    procedure SafeInitForm;
    var
      V : TVariantArray;
    begin
      SetArrayLength(V, 0);
      ThreadSafeCall('InitForm', V);
    end;

    procedure ShowInitFormModal;
    begin
      frmDesign.ShowModal;
    end;

    procedure SafeShowInitFormModal;
    var
      V : TVariantArray;
    begin
      SetArrayLength(V, 0);
      ThreadSafeCall('ShowInitFormModal', V);
    end;

    procedure MainInitForm;
    begin
      try
        SafeInitForm;
        SafeShowInitFormModal;
      finally
        FreeForm(frmDesign);
      except
        WriteLn('An error seems to have occurred in: InitForm');
      end;
    end;

    begin
      ClearDebug;
      MainInitForm;
    end.

    then we have to make two procedures to make the tcolorpicker do something so first under the Tbutton put this and add this procedure.
    SCAR Code:
    program New;

    var
      // InitForm variables.
      frmDesign : TForm;
      Button1 : TButton;
      colors : TEdit;
      colorpicker : TColorPicker;
    //add this procedure
    Procedure colorpick(sender: Tobject);
    begin
      colorpicker.Pick;
      colorpicker.onpick := @colorpicked;
    end;

    procedure InitForm;
    begin
      frmDesign := CreateForm;
      frmDesign.Position := poDesktopCenter;
      frmDesign.BorderStyle := bsSingle;
      frmDesign.Width := 300;
      frmDesign.Height := 173;
      frmDesign.Caption := 'frmDesign';
      frmDesign.Color := clBtnFace;
      frmDesign.Font.Color := clWindowText;
      frmDesign.Font.Height := -11;
      frmDesign.Font.Name := 'MS Sans Serif';
      frmDesign.Font.Style := [];
      frmDesign.PixelsPerInch := 96;
      Button1 := TButton.Create(frmDesign);
      Button1.Parent := frmDesign;
      Button1.Left := 20;
      Button1.Top := 70;
      Button1.Width := 75;
      Button1.Height := 25;
      Button1.Caption := 'Pick color';
      Button1.TabOrder := 8;
      Button1.Onclick := @colorpick;// add this
      colors := TEdit.Create(frmDesign);
      colors.Parent := frmDesign;
      colors.Left := 100;
      colors.Top := 73;
      colors.Width := 121;
      colors.Height := 21;
      colors.TabOrder := 9;
      colors.Text := 'color';
      colorpicker := Tcolorpicker.Create(frmdesign);
    end;

    procedure SafeInitForm;
    var
      V : TVariantArray;
    begin
      SetArrayLength(V, 0);
      ThreadSafeCall('InitForm', V);
    end;

    procedure ShowInitFormModal;
    begin
      frmDesign.ShowModal;
    end;

    procedure SafeShowInitFormModal;
    var
      V : TVariantArray;
    begin
      SetArrayLength(V, 0);
      ThreadSafeCall('ShowInitFormModal', V);
    end;

    procedure MainInitForm;
    begin
      try
        SafeInitForm;
        SafeShowInitFormModal;
      finally
        FreeForm(frmDesign);
      except
        WriteLn('An error seems to have occurred in: InitForm');
      end;
    end;

    begin
      ClearDebug;
      MainInitForm;
    end.
    this makes it so when you click the button it goes to the colorpicker and when it picks it goes to this next procedure. so add this one last procedure and you are done.
    SCAR Code:
    program New;

    var
      // InitForm variables.
      frmDesign : TForm;
      Button1 : TButton;
      colors : TEdit;
      colorpicker : Tcolorpicker;
    //add this
    Procedure colorpicked(Sender: TObject; Color, X, Y: Integer);
    begin
      colors.text:= inttostr(color);
    end;

    Procedure colorpick(sender: Tobject);
    begin
      colorpicker.Pick;
      colorpicker.onpick := @colorpicked;
    end;

    procedure InitForm;
    begin
      frmDesign := CreateForm;
      frmDesign.Position := poDesktopCenter;
      frmDesign.BorderStyle := bsSingle;
      frmDesign.Width := 300;
      frmDesign.Height := 173;
      frmDesign.Caption := 'frmDesign';
      frmDesign.Color := clBtnFace;
      frmDesign.Font.Color := clWindowText;
      frmDesign.Font.Height := -11;
      frmDesign.Font.Name := 'MS Sans Serif';
      frmDesign.Font.Style := [];
      frmDesign.PixelsPerInch := 96;
      Button1 := TButton.Create(frmDesign);
      Button1.Parent := frmDesign;
      Button1.Left := 20;
      Button1.Top := 70;
      Button1.Width := 75;
      Button1.Height := 25;
      Button1.Caption := 'Pick color';
      Button1.TabOrder := 8;
      Button1.Onclick := @colorpick;
      colors := TEdit.Create(frmDesign);
      colors.Parent := frmDesign;
      colors.Left := 100;
      colors.Top := 73;
      colors.Width := 121;
      colors.Height := 21;
      colors.TabOrder := 9;
      colors.Text := 'color';
      colorpicker := Tcolorpicker.Create(frmdesign);
    end;

    procedure SafeInitForm;
    var
      V : TVariantArray;
    begin
      SetArrayLength(V, 0);
      ThreadSafeCall('InitForm', V);
    end;

    procedure ShowInitFormModal;
    begin
      frmDesign.ShowModal;
    end;

    procedure SafeShowInitFormModal;
    var
      V : TVariantArray;
    begin
      SetArrayLength(V, 0);
      ThreadSafeCall('ShowInitFormModal', V);
    end;

    procedure MainInitForm;
    begin
      try
        SafeInitForm;
        SafeShowInitFormModal;
      finally
        FreeForm(frmDesign);
      except
        WriteLn('An error seems to have occurred in: InitForm');
      end;
    end;

    begin
      ClearDebug;
      MainInitForm;
    end.

    that just makes it so when it picks the color it takes the color and puts it in the color.text variable.

    and your done now have fun.

  2. #2
    Join Date
    Dec 2006
    Posts
    173
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Wow....You know forms like inside and out

    Great Tutorial, This is going to be very helpful with my new script( Macho Oak Owner)
    Starting to merchant, if you know of any good clans, PM me please.

  3. #3
    Join Date
    May 2007
    Location
    baltimore, md
    Posts
    836
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Thanks glad i could help.

  4. #4
    Join Date
    Nov 2006
    Location
    NSW, Australia
    Posts
    3,487
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Nice tutorial Jhildy...I always do it the other way Haha.
    [CENTER][img]http://signatures.mylivesignature.com/54486/113/4539C8FAAF3EAB109A3CC1811EF0941B.png[/img][/CENTER]
    [CENTER][BANANA]TSN ~ Vacation! ~ says :I Love Santy[/BANANA][/CENTER]

    [CENTER][BANANA]Raymond - Oh rilie? says :Your smart[/BANANA][/CENTER]

  5. #5
    Join Date
    May 2007
    Location
    baltimore, md
    Posts
    836
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    what way where u use the pickcolor procedure. yeh i just wanted to experiment with the new type tcolorpicker so i figured id write a tutorial.

  6. #6
    Join Date
    Jun 2007
    Location
    Mianus
    Posts
    863
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Whats Wrong?

    Hi jhildy i have done a script just like u did but something is wrong heres the script i did but i just cant get it to work i have 3 color pick's but it only works on color pick 2 so if u press pick1 it will go to color2 edit plz help if u run this script u might know what i meen this will be used in my scripts

    SCAR Code:
    program New;
    var
      frmDesign : TForm;
      UserLabel : TLabel;
      PassLabel : TLabel;
      UserEdit : TEdit;
      PassEdit : TEdit;
      StartButton : TButton;
      AutoBox : TCheckBox;
      Color : TEdit;
      Color3 : TEdit;
      Color2 : TEdit;
      Button1 : TButton;
      Button2 : TButton;
      Button3 : TButton;
      Username, Password : String;
      colorpicker : TColorPicker;

    Procedure colorpicked(Sender: TObject; Color, X, Y: Integer);
    begin
      color2.text:= inttostr(color);
    end;

    Procedure colorpick(sender: Tobject);
    begin
      colorpicker.Pick;
      colorpicker.onpick := @colorpicked;
    end;

    procedure StartClick(sender: TObject);
    begin
      Writeln('Form Is Done');
      Username := UserEdit.Text;
      Password := PassEdit.Text;
      frmDesign.ModalResult:= mrOk; // Closes the form
    end;

    procedure InitForm;
    begin
    frmDesign := CreateForm;
    frmDesign.Left := 250;
    frmDesign.Top := 114;
    frmDesign.Width := 300;
    frmDesign.Height := 300;
    frmDesign.Caption := 'Form.';
    frmDesign.Color := clBtnFace;
    frmDesign.Font.Color := clWindowText;
    frmDesign.Font.Height := -11;
    frmDesign.Font.Name := 'MS Sans Serif';
    frmDesign.Font.Style := [];
    frmDesign.Visible := False;
    frmDesign.PixelsPerInch := 96;
    UserLabel := TLabel.Create(frmDesign);
    UserLabel.Parent := frmDesign;
    UserLabel.Left := -1;
    UserLabel.Top := 0;
    UserLabel.Width := 48;
    UserLabel.Height := 13;
    UserLabel.Caption := 'Username';
    PassLabel := TLabel.Create(frmDesign);
    PassLabel.Parent := frmDesign;
    PassLabel.Left := -1;
    PassLabel.Top := 35;
    PassLabel.Width := 46;
    PassLabel.Height := 13;
    PassLabel.Caption := 'Password';
    UserEdit := TEdit.Create(frmDesign);
    UserEdit.Parent := frmDesign;
    UserEdit.Left := 60;
    UserEdit.Top := 1;
    UserEdit.Width := 100;
    UserEdit.Height := 21;
    UserEdit.Hint := 'Username';
    UserEdit.ParentShowHint := False;
    UserEdit.ShowHint := True;
    UserEdit.TabOrder := 8;
    PassEdit := TEdit.Create(frmDesign);
    PassEdit.Parent := frmDesign;
    PassEdit.Left := 60;
    PassEdit.Top := 29;
    PassEdit.Width := 100;
    PassEdit.Height := 21;
    PassEdit.Hint := 'Password';
    PassEdit.ParentShowHint := False;
    PassEdit.ShowHint := True;
    PassEdit.TabOrder := 9;
    StartButton := TButton.Create(frmDesign);
    StartButton.Parent := frmDesign;
    StartButton.Left := 83;
    StartButton.Top := 52;
    StartButton.Width := 50;
    StartButton.Height := 20;
    StartButton.Hint := 'Press Me To Start This Script.';
    StartButton.Caption := 'Start';
    StartButton.ParentShowHint := False;
    StartButton.ShowHint := True;
    StartButton.TabOrder := 10;
    AutoBox := TCheckBox.Create(frmDesign);
    AutoBox.Parent := frmDesign;
    AutoBox.Left := 68;
    AutoBox.Top := 71;
    AutoBox.Width := 97;
    AutoBox.Height := 17;
    AutoBox.Hint := 'Use AutoColors?';
    AutoBox.Caption := 'AutoColors?';
    AutoBox.Checked := True;
    AutoBox.ParentShowHint := False;
    AutoBox.ShowHint := True;
    AutoBox.State := cbChecked;
    AutoBox.TabOrder := 11;
    Color := TEdit.Create(frmDesign);
    Color.Parent := frmDesign;
    Color.Left := 0;
    Color.Top := 117;
    Color.Width := 100;
    Color.Height := 21;
    Color.Hint := 'Pick Color 1 Of Item';
    Color.ParentShowHint := False;
    Color.ShowHint := True;
    Color.TabOrder := 12;
    Color.Text := 'Color';
    Color3 := TEdit.Create(frmDesign);
    Color3.Parent := frmDesign;
    Color3.Left := 0;
    Color3.Top := 223;
    Color3.Width := 100;
    Color3.Height := 21;
    Color3.Hint := 'Pick Color 3 Of Item';
    Color3.TabOrder := 13;
    Color3.Text := 'Color3';
    Color2 := TEdit.Create(frmDesign);
    Color2.Parent := frmDesign;
    Color2.Left := 0;
    Color2.Top := 168;
    Color2.Width := 100;
    Color2.Height := 21;
    Color2.Hint := 'Pick Color 2 Of Item';
    Color2.ParentShowHint := False;
    Color2.ShowHint := True;
    Color2.TabOrder := 14;
    Color2.Text := 'Color2';
    Button1 := TButton.Create(frmDesign);
    Button1.Parent := frmDesign;
    Button1.Left := 101;
    Button1.Top := 116;
    Button1.Width := 50;
    Button1.Height := 20;
    Button1.Hint := 'Pick Color';
    Button1.Caption := 'Pick';
    Button1.ParentShowHint := False;
    Button1.ShowHint := True;
    Button1.TabOrder := 15;
    Button1.Onclick := @colorpick;
    Button2 := TButton.Create(frmDesign);
    Button2.Parent := frmDesign;
    Button2.Left := 101;
    Button2.Top := 168;
    Button2.Width := 50;
    Button2.Height := 20;
    Button2.Hint := 'Pick Color';
    Button2.Caption := 'Pick';
    Button2.ParentShowHint := False;
    Button2.ShowHint := True;
    Button2.TabOrder := 16;
    Button2.Onclick := @colorpick;
    Button3 := TButton.Create(frmDesign);
    Button3.Parent := frmDesign;
    Button3.Left := 101;
    Button3.Top := 223;
    Button3.Width := 50;
    Button3.Height := 20;
    Button3.Hint := 'Pick Color';
    Button3.Caption := 'Pick';
    Button3.ParentShowHint := False;
    Button3.ShowHint := True;
    Button3.TabOrder := 17;
    StartButton.OnClick := @StartClick;
    Button3.Onclick := @colorpick;
    colorpicker := Tcolorpicker.Create(frmdesign);
    end;

    procedure SafeInitForm;
    var
      v: TVariantArray;
    begin
      setarraylength(V, 0);
      ThreadSafeCall('InitForm', v);
    end;

    procedure ShowFormModal;
    begin
      frmDesign.ShowModal;
    end;

    procedure SafeShowFormModal;
    var
      v: TVariantArray;
    begin
      setarraylength(V, 0);
      ThreadSafeCall('ShowFormModal', v);
    end;

    begin
    SafeInitForm;
    SafeShowFormModal;


    end.

  7. #7
    Join Date
    May 2007
    Location
    baltimore, md
    Posts
    836
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Thats because you only made it change color2.text you either have to make 3 seperate procedures or think of something to do with a case.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. what would you pick?
    By kurupt916 in forum NOTA
    Replies: 17
    Last Post: 01-31-2009, 08:19 PM
  2. buying pick handle + pick head * seperate.
    By Dark_Sniper in forum Mining and Smithing
    Replies: 10
    Last Post: 11-12-2007, 03:50 AM
  3. What does TColorPicker do?
    By itSchRis917 in forum OSR Help
    Replies: 21
    Last Post: 07-17-2007, 09:52 PM
  4. Pick handle
    By ~alex~ in forum OSR Help
    Replies: 3
    Last Post: 04-18-2007, 08:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •