Entwickler-Ecke
WinForms - Color TrackBars
Delete - Mo 04.07.11 07:11
Titel: Color TrackBars
Hallo Leute,
weiß jemand wo ich mir solche TrackBar Steuerelementerunterladen kann:
http://www8.pic-upload.de/04.07.11/3w2tg8eiaseo.jpg
oder muss ich so etwas selber schreiben, wenn ja, wie geht so etwas ?
Liebe Grüße BleachRukia
Delete - Di 05.07.11 20:39
Hallo,
deine Antwort war wirklich hilfreich, habe zum Thema LinearGradientBrush folgendes im Netz gefunden:
C#-Quelltext
1: 2: 3: 4:
| LinearGradientBrush LinearGradientBrush = new LinearGradientBrush(new Rectangle(0, 0, this.panel1.Width, this.panel1.Height), Color.Red, Color.Green, LinearGradientMode.Horizontal); Graphics Graphics = Graphics.FromHwnd(this.panel1.Handle); Graphics.FillRectangle(LinearGradientBrush, new Rectangle(0, 0, this.panel1.Width, this.panel1.Height)); Graphics.Dispose(); |
Mit dieser Lösung kann ich aber nur einen Farbverlauf mit 2 Farben Maximal machen aber ich wollte ja einen Farbverlauf mit allen Farben machen, so wie es auf dem Bild ist, kennt da jemand eine Lösung ?
Liebe Grüße BleachRukia
Yogu - Di 05.07.11 22:51
Hallo,
mit
dieser Klasse [
http://richnewman.wordpress.com/hslcolor-class/] kannst du dir eine Farbe basierend auf Farbton (Hue), Helligkeit (Brightness) und Sättigung (Saturation) erstellen. Die lezten beiden kannst du auf einem konstanten Wert lassen, IMHO dürfte das 1 sein. Dann musst du nur noch in einer Schleife für jede Spalte der TrackBar eine senkrechte Linie in der bestimmten Farbe zeichnen.
Grüße,
Yogu
Th69 - Mi 06.07.11 10:05
Hallo BleachRukia,
BleachRukia hat folgendes geschrieben: |
Mit dieser Lösung kann ich aber nur einen Farbverlauf mit 2 Farben Maximal machen |
Du kannst aber mehrere LinearGradientBrush-Path Objekte nebeneinander zeichnen, z.B. rot->grün, grün->blau, blau->rot.
Und schau dir dazu auch mal die Farbleiste-Zeichnung bei
HSL-Farbraum [
http://de.wikipedia.org/wiki/HSL-Farbraum] an.
Delete - Mi 06.07.11 10:32
Hallo TH69,
so etwas habe ich mir auch schon überlegt aber gut das du es erwähnst hast, da war ich wenigstens schon mal auf dem richtigen Weg gewesen :D
Liebe Grüße BleachRukia
Delete - Mi 06.07.11 11:17
Hallo,
habe ein riesen Problem, das einfach nur unlogisch für mich ist, mit dieser Schleife male ich einen Farbverlauf:
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:
| int Position; Color Color01; Color Color02; private void button1_Click(object sender, EventArgs e) { for (int i = 0; i < 2; i++) { switch (i) { case 0: Color01 = Color.Red; Color02 = Color.Yellow; break; case 1: Color01 = Color.Yellow; Color02 = Color.Green; break;
}
LinearGradientBrush LinearGradientBrush = new LinearGradientBrush(new Rectangle(Position, 0, 60, this.panel1.Height), Color01, Color02, LinearGradientMode.Horizontal); Graphics Graphics = Graphics.FromHwnd(this.panel1.Handle); Graphics.FillRectangle(LinearGradientBrush, new Rectangle(Position, 0, 60, this.panel1.Height)); Graphics.Dispose(); Position += 60; } } |
Mit jeder Position und Breite wird mir der Farbverlauf richtig gemalt, nur nicht mit der Zahl 60 :shock: , bekomme dann immer mit Color02 einen kleinen Farbbalken als Schnitt im Farbverlauf, weiß jemand wieso ?
Liebe Grüße BleachRukia
Delete - Mi 06.07.11 13:13
Hallo,
ein besseres Beispiel für den Fehler ist dieser Code hier: (Die Breite von Panel ist 360)
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: 39: 40: 41:
| int Position; Color Color01, Color02; private void button1_Click(object sender, EventArgs e) { for (int i = 0; i < 6; i++) { switch (i) { case 0: Color01 = Color.Red; Color02 = Color.Yellow; break; case 1: Color01 = Color.Yellow; Color02 = Color.Green; break; case 2: Color01 = Color.Green; Color02 = Color.Cyan; break; case 3: Color01 = Color.Cyan; Color02 = Color.Blue; break; case 4: Color01 = Color.Blue; Color02 = Color.Magenta; break; case 5: Color01 = Color.Magenta; Color02 = Color.Red; break; }
LinearGradientBrush LinearGradientBrush = new LinearGradientBrush(new Rectangle(Position, 0, this.panel1.Width / 6, this.panel1.Height), Color01, Color02, LinearGradientMode.Horizontal); Graphics Graphics = Graphics.FromHwnd(this.panel1.Handle); Graphics.FillRectangle(LinearGradientBrush, new Rectangle(Position, 0, this.panel1.Width / 6, this.panel1.Height)); Graphics.Dispose(); Position += this.panel1.Width / 6; } } |
Liebe Grüße BleachRukia
Th69 - Mi 06.07.11 13:17
Hallo,
ich habe den Farbverlauf bei mir selber getestet und kann den selben Effekt nachvollziehen, d.h Striche im Bild. Dies scheint nicht nur bei 60 sondern auch bei anderen Schrittweiten zu passieren (ich habe dafür extra auf die Form gezeichnet, so daß ich diese in der Größe verändern kann und sich die Schrittweite (step) daran anpaßt):
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: 39: 40: 41: 42:
| private void MainForm_Paint(object sender, PaintEventArgs e) { int position = 0; int step = this.ClientSize.Width / 6; Color color01 = new Color(); Color color02 = new Color(); for (int i = 0; i < 6; i++) { switch (i) { case 0: color01 = Color.Red; color02 = Color.Yellow; break; case 1: color01 = Color.Yellow; color02 = Color.Lime; break; case 2: color01 = Color.Lime; color02 = Color.Cyan; break; case 3: color01 = Color.Cyan; color02 = Color.Blue; break; case 4: color01 = Color.Blue; color02 = Color.Magenta; break; case 5: color01 = Color.Magenta; color02 = Color.Red; break; }
Rectangle rect = new Rectangle(position, 0, step, this.ClientSize.Height+1); using(LinearGradientBrush linearGradientBrush = new LinearGradientBrush(rect, color01, color02, LinearGradientMode.Horizontal)) e.Graphics.FillRectangle(linearGradientBrush, rect); position += step; } } |
Es scheint wohl eine interne Rechenungenauigkeit beim LinearGradientBrush vorzuliegen.
Evtl bringt es ja was, auf Fließkommazahlen umzusteigen...
Edit: ja, ein bißchen besser wird es bei 'float':
C#-Quelltext
1: 2: 3: 4: 5: 6:
| float position = 0; float step = this.ClientSize.Width / 6.0f;
RectangleF rect = new RectangleF(position, 0, step, this.ClientSize.Height+1); |
aber bei einigen wenigen Schrittweiten bleiben trotzdem ein paar Striche übrig :gruebel:
Delete - Mi 06.07.11 13:24
Hallo,
wie hast den du das jetzt hinbekommen das keine Schnittstellen angezeigt werden, habe deinen Code ausprobiert, aber bekomme wieder den selben Fehler !?
Liebe Grüße BleachRukia
Th69 - Mi 06.07.11 13:32
Hallo,
bei 59 und 60 kriege ich auch weiterhin die Striche, aber bei 58 bzw. 61 nicht.
Teste das mal bei dir aus.
Delete - Mi 06.07.11 13:34
Hallo,
das weiß ich auch aber die Farben sollen ja mit der Breite des Controls übereinstimmen.
Liebe Grüße BleachRukia
ps. Wenn das so weitergeht werde ich mir ein Bild von einem Farbverlauf herunterladen und als Backgroundimage setzen lol
Delete - Mi 06.07.11 17:32
Hallo,
tausend dank, jetzt funktioniert es richtig :D
Mit diesem Code hier kann ich unabhängig von der Größe, in jedes Control meinen Farbverlauf malen:
http://www8.pic-upload.de/06.07.11/owu39xt549z4.jpg
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: 39: 40: 41: 42:
| int Position; Color Color01, Color02; private void button1_Click(object sender, EventArgs e) { for (int i = 0; i < 6; i++) { switch (i) { case 0: Color01 = Color.Red; Color02 = Color.Yellow; break; case 1: Color01 = Color.Yellow; Color02 = Color.Green; break; case 2: Color01 = Color.Green; Color02 = Color.Cyan; break; case 3: Color01 = Color.Cyan; Color02 = Color.Blue; break; case 4: Color01 = Color.Blue; Color02 = Color.Magenta; break; case 5: Color01 = Color.Magenta; Color02 = Color.Red; break; }
LinearGradientBrush LinearGradientBrush = new LinearGradientBrush(new Rectangle(Position, 0, this.panel1.Width / 6, this.panel1.Height), Color01, Color02, LinearGradientMode.Horizontal); LinearGradientBrush.WrapMode = WrapMode.TileFlipX; Graphics Graphics = Graphics.FromHwnd(this.panel1.Handle); Graphics.FillRectangle(LinearGradientBrush, new Rectangle(Position, 0, this.panel1.Width / 6, this.panel1.Height)); Graphics.Dispose(); Position += this.panel1.Width / 6; } } |
Jetzt habe ich aber folgendes Problem, wie ihr auf dem Bild sicher sehen könnt, schaut die Linie an dem der Slider entlang fährt auf beiden Seiten
etwas heraus(Combo aus Panel und TrackBar), dies muss so sein das der Slider genau mit dem Pfeil an die erste oder letzte Position zeigt, nur leider stört mich das sehr das es an beiden Seiten herausschaut, die Sliders in den Links von TH69 haben mir jetzt auch nicht wirklich zugesagt, was ich aber komisch finde ist, die Sliders von Photoshop habe ich schon in ganz vielen Programmen gesehen, machen die die alle selber oder laden die sich die Slider irgendwo herunter, wenn nicht wie kann ich solche Slider selber machen die dann genauso ausehen ?
Liebe Grüße BleachRukia
Delete - Mi 06.07.11 19:03
Hallo,
genau das meine ich, genau nach so etwas habe ich gesucht, weißt du wie ich so etwas in mein Programm reinbekomme ?
Liebe Grüße BleachRukia
PS. Vielen dank mit dem Tipp, nur im Paint Event Zeichnen :D
Delete - Sa 09.07.11 15:39
Hallo Leute,
in den letzten Tagen habe ich mich intensive mit dem Tehma Color Sliders beschäftigt und Projekte wie dieses gefunden:
http://www.avengersutd.com/blog/2010/10/custom-color-chooserpicker-dialog-with-alpha-slider-for-windows-forms-in-c/
Habe jetzt meinen eigenen ColorSlider mit diesem Code geschrieben:
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: 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: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96:
| using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.Text; using System.Windows.Forms;
namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
int Position; Color Color01, Color02; private void panel1_Paint(object sender, PaintEventArgs e) { for (int i = 0; i < 6; i++) { switch (i) { case 0: Color01 = Color.Red; Color02 = Color.Yellow; break; case 1: Color01 = Color.Yellow; Color02 = Color.Green; break; case 2: Color01 = Color.Green; Color02 = Color.Cyan; break; case 3: Color01 = Color.Cyan; Color02 = Color.Blue; break; case 4: Color01 = Color.Blue; Color02 = Color.Magenta; break; case 5: Color01 = Color.Magenta; Color02 = Color.Red; break; }
Rectangle Rectangle = new Rectangle(Position, 0, this.panel1.Width / 6, this.panel1.Height); LinearGradientBrush LinearGradientBrush = new LinearGradientBrush(Rectangle, Color01, Color02, LinearGradientMode.Horizontal); LinearGradientBrush.WrapMode = WrapMode.TileFlipX; e.Graphics.FillRectangle(LinearGradientBrush, Rectangle); Position += this.panel1.Width / 6; } }
int MouseX; private void Form1_Paint(object sender, PaintEventArgs e) { Point[] Triangle = { new Point(this.panel1.Location.X - 6 + MouseX, this.panel1.Location.Y + this.panel1.Height + 10), new Point(this.panel1.Location.X + 6 + MouseX, this.panel1.Location.Y + this.panel1.Height + 10), new Point(this.panel1.Location.X + MouseX, this.panel1.Location.Y + this.panel1.Height) }; e.Graphics.FillPolygon(new SolidBrush(Color.DarkGray), Triangle); }
private void Form1_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (e.Y >= this.panel1.Location.Y + this.panel1.Height && e.Y <= this.panel1.Location.Y + this.panel1.Height + 10) { if (e.X >= this.panel1.Location.X && e.X <= this.panel1.Location.X + this.panel1.Width) { MouseX = e.X - this.panel1.Location.X; } else if (e.X <= this.panel1.Location.X) { MouseX = 0; } else if (e.X >= this.panel1.Location.X + this.panel1.Width) { MouseX = 200; }
this.Refresh(); this.Text = MouseX.ToString(); } } } } } |
Mit diesem Code kann ich den Vrogang wunderbar darstellen nur mit 2 Einschränkungen/Probleme.
Das 1. wäre, wenn ich das Dreieck bewege, dann muss neu gezeichnet werden, das funktioniert auch gut beim Dreieck nur leider löscht das Programm dann den Farbverlauf, kennt Jemand eine alternative/Lösung zu Refresh zum neu zeichnen ?
Das 2. wäre, das das Ergeniss des Dreiecks immer der Min/Max Wert der Breite des Panels ist, aber ich wollte es so machen das es immer unabhängig von der Breite des Panels von 0 bis 360 geht.
Liebe Grüße BleachRukia
Delete - Sa 09.07.11 18:13
Hallo,
habe das Problem mit der Farbe halb gelöst, der Positions Wert musste einfach bei jedem Paint Event wieder auf 0 gesetzt werden, nur leider flackert das Panel jetzt bei jedem Paint Event :(
Liebe Grüße BleachRukia
Delete - Sa 09.07.11 20:36
Hallo Leute,
habe das Problem mit dem flackern gelöst, anstatt immer wieder alles neu zu zeichnen, rufe ich mit diesem Code hier:
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: 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: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97:
| using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.Text; using System.Windows.Forms;
namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
int Position; Color Color01, Color02; private void panel1_Paint(object sender, PaintEventArgs e) { for (int i = 0; i < 6; i++) { switch (i) { case 0: Color01 = Color.Red; Color02 = Color.Yellow; break; case 1: Color01 = Color.Yellow; Color02 = Color.Green; break; case 2: Color01 = Color.Green; Color02 = Color.Cyan; break; case 3: Color01 = Color.Cyan; Color02 = Color.Blue; break; case 4: Color01 = Color.Blue; Color02 = Color.Magenta; break; case 5: Color01 = Color.Magenta; Color02 = Color.Red; break; }
Rectangle Rectangle = new Rectangle(Position, 0, this.panel1.Width / 6, this.panel1.Height); LinearGradientBrush LinearGradientBrush = new LinearGradientBrush(Rectangle, Color01, Color02, LinearGradientMode.Horizontal); LinearGradientBrush.WrapMode = WrapMode.TileFlipX; e.Graphics.FillRectangle(LinearGradientBrush, Rectangle); Position += this.panel1.Width / 6; } }
int MouseX; private void Form1_Paint(object sender, PaintEventArgs e) { Point[] Triangle = { new Point(this.panel1.Location.X - 6 + MouseX, this.panel1.Location.Y + this.panel1.Height + 10), new Point(this.panel1.Location.X + 6 + MouseX, this.panel1.Location.Y + this.panel1.Height + 10), new Point(this.panel1.Location.X + MouseX, this.panel1.Location.Y + this.panel1.Height) }; e.Graphics.Clear(Color.FromArgb(45, 45, 45)); e.Graphics.FillPolygon(new SolidBrush(Color.Gray), Triangle); }
private void Form1_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (e.Y >= this.panel1.Location.Y + this.panel1.Height && e.Y <= this.panel1.Location.Y + this.panel1.Height + 10) { if (e.X >= this.panel1.Location.X && e.X <= this.panel1.Location.X + this.panel1.Width) { MouseX = e.X - this.panel1.Location.X; } else if (e.X <= this.panel1.Location.X) { MouseX = 0; } else if (e.X >= this.panel1.Location.X + this.panel1.Width) { MouseX = 200; }
this.Invalidate(); this.Text = MouseX.ToString() + " - " + "ColorSlider"; } } } } } |
immer nur das Paint Event der Form auf :D
Liebe Grüße BleachRukia
Delete - So 10.07.11 18:51
Hallo Leute,
habe es endlich hinbekommen meine eigenen ColorSlider zu machen :D:
http://www7.pic-upload.de/10.07.11/4f18aebi9bnh.jpg
Jetzt fehlt nur noch eine Sache, dann ist es perfekt, wenn ich im Hue Bereich eine Farbe auswähle möchte ich das die Farbstärke und auch der HelligkeitsSlider automatisch ihren Farbverlauf anpassen, wenn ich z.b. im Hue Bereich den FarbWert 58 habe, wie kann ich dann den Wert wieder in einen RGB Wert konvertieren, sodass ich dann wieder mit dem Farbverlauf Color.FromARGB(konvertierter Hue Wert zu RGB) zeichnen kann ?
Liebe Grüße BleachRukia
Th69 - So 10.07.11 20:51
Hallo,
such mal nach "C# HSV RGB" im Internet.
Hier im Forum habe ich dazu diesen Beitrag
http://www.c-sharp-forum.de/viewtopic.php?p=628812#628812 gefunden.
P.S: bezogen auf deinen Screenshot: negative Farb- und Helligkeitswerte sind eher unüblich (normal von 0 bis 1 bzw. 0 bis 360 bzw. 0 bis 100)
Ansonsten sieht es aber schon sehr stylisch aus :zustimm:
Delete - Mo 11.07.11 00:21
Hallo TH69,
vielen vielen dank für den Link, werde in mir anschauen.
Habe beim Farbton MinWert = -180 und MaxWert = 180 und bei den anderen beiden, MinWert = -100 und Maxwert = 100.
Aber die Panels müssen immer die Breite von 200 haben, sonst klappt das nicht Werten :D
Liebe Grüße BleachRukia
Ps. Benutze diese ColorSlider nicht um eine eigene Farbe zu erstellen sondern die eines Bildes zu verändern :D
Delete - Mo 11.07.11 01:52
Hallo Leute,
habe jetzt einen ziemlich genialen Code für HSV zu RGB gefunden:
http://stackoverflow.com/questions/1335426/is-there-a-built-in-c-net-system-api-for-hsv-to-rgb
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:
| public static Color ColorFromHSV(double hue, double saturation, double value) { int hi = Convert.ToInt32(Math.Floor(hue / 60)) % 6; double f = hue / 60 - Math.Floor(hue / 60);
value = value * 255; int v = Convert.ToInt32(value); int p = Convert.ToInt32(value * (1 - saturation)); int q = Convert.ToInt32(value * (1 - f * saturation)); int t = Convert.ToInt32(value * (1 - (1 - f) * saturation));
if (hi == 0) return Color.FromArgb(255, v, t, p); else if (hi == 1) return Color.FromArgb(255, q, v, p); else if (hi == 2) return Color.FromArgb(255, p, v, t); else if (hi == 3) return Color.FromArgb(255, p, q, v); else if (hi == 4) return Color.FromArgb(255, t, p, v); else return Color.FromArgb(255, v, p, q); } |
Nur leider ist jetzt mein Problem das ich einen Code gesucht habe für HSL zu RGB, also einfach nur das der V Wert bei HSV über 1 gehen kann um das Bild heller zu machen.
Kennt Jemand eine Lösung wie man den Code zu HSL umschreiben kann ?
Liebe Grüße BleachRukia
Delete - Mo 11.07.11 17:23
Hallo Leute,
habe jetzt leider nichts funktionierendes zum Thema HSL zu RGB gefunden, war jetzt auch nicht so wichtig gewesen, Photoshop macht das auch nur bei HSV, wenn es darum geht eigene Farben zu erstellen.
Aber die Frage zu diesem Thema ist eigentlich schon längst beantwortet :D
Hier mal der Code für die Color Sliders: (Die Panels müssen immer eine Breite von 200 haben)
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: 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: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216:
| using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.Text; using System.Windows.Forms;
namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); this.Select(); }
int DrawPosition; Color Color01, Color02; private void HuePanel_Paint(object sender, PaintEventArgs e) { for (int i = 0; i < 6; i++) { switch (i) { case 0: Color01 = Color.Red; Color02 = Color.Yellow; break; case 1: Color01 = Color.Yellow; Color02 = Color.Green; break; case 2: Color01 = Color.Green; Color02 = Color.Cyan; break; case 3: Color01 = Color.Cyan; Color02 = Color.Blue; break; case 4: Color01 = Color.Blue; Color02 = Color.Magenta; break; case 5: Color01 = Color.Magenta; Color02 = Color.Red; break; }
Rectangle Rectangle = new Rectangle(DrawPosition, 0, this.HuePanel.Width / 6, this.HuePanel.Height); LinearGradientBrush LinearGradientBrush = new LinearGradientBrush(Rectangle, Color01, Color02, LinearGradientMode.Horizontal); LinearGradientBrush.WrapMode = WrapMode.TileFlipX; e.Graphics.FillRectangle(LinearGradientBrush, Rectangle); DrawPosition += this.HuePanel.Width / 6; } }
private void SaturationPanel_Paint(object sender, PaintEventArgs e) { Rectangle Rectangle = new Rectangle(0, 0, this.SaturationPanel.Width, this.SaturationPanel.Height); LinearGradientBrush LinearGradientBrush = new LinearGradientBrush(Rectangle, Color.White, Color.Red, LinearGradientMode.Horizontal); LinearGradientBrush.WrapMode = WrapMode.TileFlipX; e.Graphics.FillRectangle(LinearGradientBrush, Rectangle); }
private void BrightnessPanel_Paint(object sender, PaintEventArgs e) { Rectangle Rectangle = new Rectangle(0, 0, this.BrightnessPanel.Width, this.BrightnessPanel.Height); LinearGradientBrush LinearGradientBrush = new LinearGradientBrush(Rectangle, Color.Black, Color.Red, LinearGradientMode.Horizontal); LinearGradientBrush.WrapMode = WrapMode.TileFlipX; e.Graphics.FillRectangle(LinearGradientBrush, Rectangle); }
int HueArrow = 0; int SaturationArrow = 100; int BrightnessArrow = 0; private void Form1_Paint(object sender, PaintEventArgs e) { Point[] HueTriangle = { new Point(this.HuePanel.Location.X + this.HuePanel.Width / 2 - 6 + HueArrow, this.HuePanel.Location.Y + this.HuePanel.Height + 10), new Point(this.HuePanel.Location.X + this.HuePanel.Width / 2 + 6 + HueArrow, this.HuePanel.Location.Y + this.HuePanel.Height + 10), new Point(this.HuePanel.Location.X + this.HuePanel.Width / 2 + HueArrow, this.HuePanel.Location.Y + this.HuePanel.Height) }; e.Graphics.FillPolygon(new SolidBrush(Color.Gray), HueTriangle);
Point[] SaturationTriangle = { new Point(this.SaturationPanel.Location.X - 6 + SaturationArrow, this.SaturationPanel.Location.Y + this.SaturationPanel.Height + 10), new Point(this.SaturationPanel.Location.X + 6 + SaturationArrow, this.SaturationPanel.Location.Y + this.SaturationPanel.Height + 10), new Point(this.SaturationPanel.Location.X + SaturationArrow, this.SaturationPanel.Location.Y + this.SaturationPanel.Height) }; e.Graphics.FillPolygon(new SolidBrush(Color.Gray), SaturationTriangle);
Point[] BrightnessTriangle = { new Point(this.BrightnessPanel.Location.X + this.BrightnessPanel.Width / 2 - 6 + BrightnessArrow, this.BrightnessPanel.Location.Y + this.BrightnessPanel.Height + 10), new Point(this.BrightnessPanel.Location.X + this.BrightnessPanel.Width / 2 + 6 + BrightnessArrow, this.BrightnessPanel.Location.Y + this.BrightnessPanel.Height + 10), new Point(this.BrightnessPanel.Location.X + this.BrightnessPanel.Width / 2 + BrightnessArrow, this.BrightnessPanel.Location.Y + this.BrightnessPanel.Height) }; e.Graphics.FillPolygon(new SolidBrush(Color.Gray), BrightnessTriangle); }
private void Form1_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (e.Y >= this.HuePanel.Location.Y + this.HuePanel.Height && e.Y <= this.HuePanel.Location.Y + this.HuePanel.Height + 10) { if (e.X >= this.HuePanel.Location.X && e.X <= this.HuePanel.Location.X + this.HuePanel.Width) { HueArrow = e.X - this.HuePanel.Location.X - this.HuePanel.Width / 2; } else if (e.X <= this.HuePanel.Location.X) { HueArrow = -100; } else if (e.X >= this.HuePanel.Location.X + this.HuePanel.Width) { HueArrow = 100; }
this.HueTextBox.Text = Convert.ToString(HueArrow * 18 / 10); }
if (e.Y >= this.SaturationPanel.Location.Y + this.SaturationPanel.Height && e.Y <= this.SaturationPanel.Location.Y + this.SaturationPanel.Height + 10) { if (e.X >= this.SaturationPanel.Location.X && e.X <= this.SaturationPanel.Location.X + this.SaturationPanel.Width) { SaturationArrow = e.X - this.SaturationPanel.Location.X; } else if (e.X <= this.SaturationPanel.Location.X) { SaturationArrow = 0; } else if (e.X >= this.SaturationPanel.Location.X + this.SaturationPanel.Width) { SaturationArrow = 200; }
this.SaturationTextBox.Text = Convert.ToString(SaturationArrow - 100); }
if (e.Y >= this.BrightnessPanel.Location.Y + this.BrightnessPanel.Height && e.Y <= this.BrightnessPanel.Location.Y + this.BrightnessPanel.Height + 10) { if (e.X >= this.BrightnessPanel.Location.X && e.X <= this.BrightnessPanel.Location.X + this.BrightnessPanel.Width) { BrightnessArrow = e.X - this.BrightnessPanel.Location.X - this.BrightnessPanel.Width / 2; } else if (e.X <= this.SaturationPanel.Location.X) { BrightnessArrow = -100; } else if (e.X >= this.BrightnessPanel.Location.X + this.BrightnessPanel.Width) { BrightnessArrow = 100; }
this.BrightnessTextBox.Text = Convert.ToString(BrightnessArrow); }
this.Invalidate(); } }
private void HueTextBox_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (Convert.ToInt32(this.HueTextBox.Text) < -180) { this.HueTextBox.Text = "-180"; } else if (Convert.ToInt32(this.HueTextBox.Text) > 180) { this.HueTextBox.Text = "180"; }
HueArrow = Convert.ToInt32(this.HueTextBox.Text) / 18 * 10; this.Invalidate(); } }
private void SaturationTextBox_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (Convert.ToInt32(this.SaturationTextBox.Text) < -100) { this.SaturationTextBox.Text = "-100"; } else if (Convert.ToInt32(this.SaturationTextBox.Text) > 100) { this.SaturationTextBox.Text = "100"; }
SaturationArrow = Convert.ToInt32(this.SaturationTextBox.Text) + 100; this.Invalidate(); } }
private void BrightnessTextBox_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (Convert.ToInt32(this.BrightnessTextBox.Text) < -100) { this.BrightnessTextBox.Text = "-100"; } else if (Convert.ToInt32(this.BrightnessTextBox.Text) > 100) { this.BrightnessTextBox.Text = "100"; }
BrightnessArrow = Convert.ToInt32(this.BrightnessTextBox.Text); this.Invalidate(); } } } } |
Liebe Grüße BleachRukia
Entwickler-Ecke.de based on phpBB
Copyright 2002 - 2011 by Tino Teuber, Copyright 2011 - 2025 by Christian Stelzmann Alle Rechte vorbehalten.
Alle Beiträge stammen von dritten Personen und dürfen geltendes Recht nicht verletzen.
Entwickler-Ecke und die zugehörigen Webseiten distanzieren sich ausdrücklich von Fremdinhalten jeglicher Art!