Autor Beitrag
bo_91
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 43

Win XP - Win8
C#, PHP, VB, Java
BeitragVerfasst: Di 22.01.13 23:59 
Hallo zusammen...

Ich stehe momentan vor einem ich denke mal keinen Rätsel jedoch bin ich bis jetzt nicht drauf gekommen...

Ich habe ein TabControl mit ein paar TabPages. die TabPages setze ich auf weiss

ausblenden C#-Quelltext
1:
TabPagexy.BackColor = Color.White;					


Nun möchte ich aber den Header des aktiven Tabs auch weiss haben... da habe ich aber noch keine Lösung gefunden

Schon mal vielen Dank für eure Hilfe

mfg
bo_91
Einloggen, um Attachments anzusehen!
DarkStaRX
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28
Erhaltene Danke: 3



BeitragVerfasst: Mi 23.01.13 00:56 
Also ich habe folgendes gefunden

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
private Dictionary<TabPage, Color> TabColors = new Dictionary<TabPage, Color>();
private void SetTabHeader(TabPage page, Color color)
{
  TabColors[page] = color;
  tabControl1.Invalidate();
}


Dann im tabpages DrawItem (tabControl.DrawMode auf OwnerDrawFixed setzen)
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
using (Brush br = new SolidBrush(TabColors[tabControl1.TabPages[e.Index]]))
{
  e.Graphics.FillRectangle(br, e.Bounds);
  SizeF sz = e.Graphics.MeasureString(tabControl1.TabPages[e.Index].Text, e.Font);
  e.Graphics.DrawString(tabControl1.TabPages[e.Index].Text, e.Font, Brushes.Black, e.Bounds.Left + (e.Bounds.Width - sz.Width) / 2, e.Bounds.Top + (e.Bounds.Height - sz.Height) / 2 + 1);

  Rectangle rect = e.Bounds;
  rect.Offset(01);
  rect.Inflate(0, -1);
  e.Graphics.DrawRectangle(Pens.DarkGray, rect);
  e.DrawFocusRectangle();
}


Anschließend mit selectedIndexChange Ereignis
ausblenden C#-Quelltext
1:
2:
//Farbe von der Tabpage setzen
SetTabHeader(tabControl1.TabPages[0], Color.White);


Moderiert von user profile iconTh69: Highlight- durch C#-Tags ersetzt
bo_91 Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 43

Win XP - Win8
C#, PHP, VB, Java
BeitragVerfasst: Mi 23.01.13 01:58 
Hmm irgendwie finde ich das komisch in VisualStudio habe ich das Problem mit den Tabs gar nicht, sondern nur wenn ich in MonoDevelop entwickle...

aber ja ich habe jetzt mal schnell folgendes gemacht...

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:
36:
37:
38:
public class Tab : TabControl
  {

    public Tab ()
    {
      this.Anchor = AnchorStyles.Top;
      this.Dock = DockStyle.Top;
      this.DrawMode = TabDrawMode.OwnerDrawFixed;
      this.DrawItem += HandleDrawItem;
    }

    private void HandleDrawItem (object sender, DrawItemEventArgs e)
    {
      Color color;
      if (e.Index == this.SelectedIndex) 
        color = Color.White;
      else color = Color.FromArgb(240,240,240);

      using (Brush br = new SolidBrush(color)) {
        e.Graphics.FillRectangle (br, e.Bounds);
        SizeF sz = e.Graphics.MeasureString (this.TabPages [e.Index].Text, e.Font);
        e.Graphics.DrawString (this.TabPages [e.Index].Text, e.Font, Brushes.Black, e.Bounds.Left + (e.Bounds.Width - sz.Width) / 2, e.Bounds.Top + (e.Bounds.Height - sz.Height) / 2 + 1);
        
        Rectangle rect = e.Bounds;
        rect.Offset (01);
        rect.Inflate (0, -1);
        e.Graphics.DrawRectangle (Pens.LightGray, rect);
        e.DrawFocusRectangle();
      }
    }

    public void add(string name){
      TabPage tp = new TabPage(name);
      tp.BackColor = Color.White;
      
      this.Controls.Add(tp);
    }
}


Ich bin somit schon nahe an dem was ich will... nun habe jedoch noch ein paar ungewollte Linien (siehe Bild, gelbe Markierung)... wie bringe ich diese weg?


mfg
bo91
Einloggen, um Attachments anzusehen!
bo_91 Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 43

Win XP - Win8
C#, PHP, VB, Java
BeitragVerfasst: Mi 23.01.13 09:58 
Bin nun selber drauf gekommen, war gestern wohl zu müde um das noch zu sehen :shock:

Der Vollständigkeit zu liebe:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
private void HandleDrawItem (object sender, DrawItemEventArgs e)
    {
      Color color;
      if (e.Index == this.SelectedIndex) 
        color = Color.White;
      else color = Color.FromArgb(240,240,240);

      using (Brush br = new SolidBrush(color)) {
        e.Graphics.FillRectangle (br, e.Bounds);
        SizeF sz = e.Graphics.MeasureString (this.TabPages [e.Index].Text, e.Font);
        e.Graphics.DrawString (this.TabPages [e.Index].Text, e.Font, Brushes.Black, e.Bounds.Left + (e.Bounds.Width - sz.Width) / 2, e.Bounds.Top + (e.Bounds.Height - sz.Height) / 2 + 1);
        
        //Rectangle rect = e.Bounds;
        //rect.Offset (0, 1);
        //rect.Inflate (0, -1);
        //e.Graphics.DrawRectangle (Pens.LightGray, rect);    <------ Hier einfach das zeichnen des Rechtecks weglassen und dann hat man auch diese misteriösen Linien nicht
        e.DrawFocusRectangle();
      }
    }



Aber wieso das ein TabControl welches ich im VS erstelle anders aussieht als wenn ich es (mit demselben Code) im MonoDevelop erzeuge wird mir wohl ein Rätsel bleiben...

mfg
bo_91