Autor Beitrag
JayK
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1013



BeitragVerfasst: So 28.05.06 21:47 
Hallo,

ich versuche gerade so etwas wie einen SpeedButton zu programmieren, der dasselbe Design wie ein ToolStripButton haben soll.
Die Dinger sind normalerweise transparent - bis auf den Glyph natürlich - und der Hintergrund (der TB-Gradient) scheint durch. Wenn man mit der Maus drüberfährt gibt es einen soliden Rand und eine halbtransparente Füllung. Beim MouseDown ne dunklere Füllung und Rand.
Die Färbungen sind alles kein Problem, so nach und nach kriegt man die raus, was ich nicht hinbekomme ist die Tranzparenz.
Wenn ich einfach garnüscht zeichne, dann bleibt der Hover-effekt nach dem MouseLeave logischerweise bestehen. Zeichne ich mit FillRectangle und Color.Transparent drüber, isses derselbe Effekt.
Ich müsste quasi das Parent Control an der Stelle drüberzeichnen lassen und dann mein Image draufbringen. Aber wie macht man das?

Code bisher:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
protected override void OnPaint(PaintEventArgs pevent)
    {
      if (mouseDown || mouseOver)
      {
        if (mouseDown)
        {
          baseBackground = new SolidBrush(SystemColors.ControlDark); // die Farbe ist btw. noch nicht sicher
        }
        else
        {
          Color c = Color.FromArgb(128, SystemColors.Highlight.R, SystemColors.Highlight.G, SystemColors.Highlight.B);
          baseBackground = new SolidBrush(c);
        }
        pevent.Graphics.FillRectangle(baseBackground, ClientRectangle);
        pevent.Graphics.DrawRectangle(new Pen(SystemColors.Highlight), new Rectangle(00, ClientSize.Width - 1, ClientSize.Height - 1));
      }
      if (Image != null)
      {
        pevent.Graphics.DrawImage(Image, new Point(ClientSize.Width / 2 - Image.Size.Width / 2, ClientSize.Height / 2 - Image.Height / 2));
      }
      pevent.Graphics.Flush();
    }


Vielen Dank für Hilfe
JayK
JayK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1013



BeitragVerfasst: Do 08.06.06 21:23 
Ich hab immer noch keine Idee :(
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Fr 09.06.06 15:07 
Hallo!

Irgendwie kann ich mir das gerade nicht vorstellen. Könntest Du das Projekt (Quellcode) eventuell einmal anhängen, dann könnte man auch noch ein bisschen mit rumspielen um Lösungen zu finden.

Grüße
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
JayK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1013



BeitragVerfasst: So 11.06.06 18:41 
Quellcode:

ausblenden volle Höhe C#-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:
class MyButton : Button {

protected Brush baseBackground = null;
protected bool mouseOver, mouseDown = false;

protected override void OnPaint(PaintEventArgs pevent)
{
  if (mouseDown || mouseOver)  // werden bei den jeweiligen Events festgelegt
  {
    if (mouseDown)  // ebenfalls
    {
      baseBackground = new SolidBrush(SystemColors.ControlDark);
    }
    else
    {
      Color c = Color.FromArgb(128, SystemColors.Highlight.R, SystemColors.Highlight.G, SystemColors.Highlight.B);
      baseBackground = new SolidBrush(c);
    }
    pevent.Graphics.FillRectangle(baseBackground, ClientRectangle);
    pevent.Graphics.DrawRectangle(new Pen(SystemColors.Highlight), new Rectangle(00, ClientSize.Width - 1, ClientSize.Height - 1));
  }
  else
  {
    // hier müsste dafür gesorgt werden, dass das Control  hinter der Komponente zu sehen ist
    // wenn also die Kompo über einer Textbox steht, dann soll man diese nun sehen
    // das ganze soll auch mit gradienten gehen, deshalb kann ich mir keine einfache Farbe von wo holen
  }
  if (Image != null)
  {
    pevent.Graphics.DrawImage(Image, new Point(ClientSize.Width / 2 - Image.Size.Width / 2, ClientSize.Height / 2 - Image.Height / 2));
  }

}

}


|EDIT: Abgeleitete Klasse vegessen mitzukopieren
JayK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1013



BeitragVerfasst: Mi 21.06.06 15:04 
Immer noch nicht vorstellbar?
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mi 21.06.06 15:08 
Vorstellbar schon, auch wenn man dem Code oben noch ein paar Dinge hinzufügen muss, damit er überhaupt was tut. Allerdings habe ich auch keine Lösung finden können.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
JayK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1013



BeitragVerfasst: Mi 21.06.06 15:17 
user profile iconChristian S. hat folgendes geschrieben:
auch wenn man dem Code oben noch ein paar Dinge hinzufügen muss

:shock: Die da wären? (außer die Events, wo mouseDown etc gesetzt werden)

user profile iconChristian S. hat folgendes geschrieben:
Allerdings habe ich auch keine Lösung finden können.

Schade :(