Autor Beitrag
AlexBegin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: Fr 08.05.09 17:22 
Über das erste Fenster (Form1) möchte ich mittels ColorDialog die Hintergrundfarbe von dem zweiten Fenster (Form2) verändern.
Den Aufruf von ColorDialog funktioniert schon, aber die Farbe wird nicht in das zweite Fenster übernommen.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.Button2Click(Sender: TObject);
begin
  if ColorDialog1.Execute then
    begin
        Form2.Color := ColorDialog1.Color;
    end;
end;


Kann mir jemand bei dem Problem helfen?


Bis dann Alex

Moderiert von user profile iconmatze: Code- durch Delphi-Tags ersetzt
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 08.05.09 17:35 
Der Quelltext ist soweit korrekt denke ich, aber die Frage ist wie du das zweite Formular anzeigst. Wenn Form2 nicht auf die angezeigte Instanz des zweiten Formulars zeigt, dann funktioniert das so nicht.
AlexBegin Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: Fr 08.05.09 17:44 
Das erste Fenster ist ein MDIForm und das zweite Fenster ist ein MDIChild.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 08.05.09 17:45 
Dann wäre ActiveMDIChild wohl eher passend zum Zugriff auf das Kindfenster. Auf jeden Fall erzeugst du das Kindfenster ja manuell, und vermutlich zeigt Form2 wie gesagt nicht auf die richtige Instanz.
Hugo343
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 114
Erhaltene Danke: 2

Windows 7
Turbo Delphi, Dev C++
BeitragVerfasst: Fr 08.05.09 17:54 
Ich bin mir nicht sicher unter welchen Vorraussetzungen du arbeitest Alex, aber bei mir dein Quelltext eigentlich gut funktioniert. Wie öffnest du Form2?
AlexBegin Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: Fr 08.05.09 17:59 
Jetzt habe ich beide Fenster das FormStyle wieder auf Normal gestellt. Jetzt funktioniert es.
Aber wie kann ich das zweite Fenster an das erste Fenster andocken?

---Moderiert von user profile iconNarses: Beiträge zusammengefasst---

An Hugo343:
Ich habe mir zwei Forms erstellt. Bei dem einen das FormStyle auf fsMDIForm und das zweite Form auf fsMDIChild gesetzt. Wenn ich nun das Programm starte werden beide Fenster gleichzeitig aufgerufen.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 08.05.09 18:03 
Das ist doch gar nicht notwendig das ohne MDI zu machen, du musst es nur richtig machen, aber wenn du nicht zeigst wie du das zweite Fenster benutzt, dann kann dir da auch niemand dabei helfen... Warum es nicht klappt, habe ich ja bereits geschrieben.

Wenn ich einfach nur den FormStyle setze, dann funktioniert es jedenfalls denke ich, aber sobald man mehr Kindfenster erstellt (was ja der Sinn von MDI ist) klappt das so nicht. Sonst häng doch einfach einmal das Projekt an. Und welche Delphiversion benutzt du?
AlexBegin Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: Fr 08.05.09 18:09 
Am Besten zeige ich euch den ganzen Code des Form1. Form2 hat nur einige Memos drin.
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ActnMan, ActnColorMaps;

type
  TForm1 = class(TForm)
    GroupBox1: TGroupBox;
    Button1: TButton;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    OpenDialog1: TOpenDialog;
    ColorDialog1: TColorDialog;
    Button2: TButton;
    procedure RadioButton1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure RadioButton2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
    begin
      Form2.Image1.Align := alClient;
      Form2.Image1.Picture.LoadFromFile(OpenDialog1.Filename);
    end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  if ColorDialog1.Execute then
    begin
        Form2.Color := ColorDialog1.Color;
    end;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  Button1.Enabled := False;
  Button2.Enabled := False;
end;

procedure TForm1.RadioButton1Click(Sender: TObject);
begin
  Button1.Enabled := True;
  Button2.Enabled := False;
end;

procedure TForm1.RadioButton2Click(Sender: TObject);
begin
  Button1.Enabled := False;
  Button2.Enabled := True;
end;

end.

Moderiert von user profile iconNarses: Code- durch Delphi-Tags ersetzt
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 08.05.09 18:11 
Und der Zugriff auf Form2.Image1 klappt? Ich habe es gerade ausprobiert, der Quelltext funktioniert so mit MDI. :nixweiss:
AlexBegin Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: Fr 08.05.09 18:17 
Mit Form2.Image1 klappt es einwandfrei. Wie gesagt, wenn ich beide Forms mit MDI laufen lasse, funktioniert es nicht.Deswegen habe ich es wieder auf normal umgestellt.
Meine Delphi-Version ist eine Turbo-Version 10.0.2288.42451 Update 2 (2006).
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 08.05.09 18:26 
Bei mir klappt das problemlos, im Anhang das entsprechende Projekt. Ich habe nur FormStyle gesetzt und den Quelltext hinzugefügt.

Aber wie gesagt, bei mehreren Childfenstern brauchst du eher ActiveMDIChild.
Einloggen, um Attachments anzusehen!