Windows Azure Cloud Storage ermöglicht es Ihnen bereits ab 0,10€ pro GB/Monat die Vorteile der Cloud zu nutzen.
Willkommen bei dotnet-snippets.de! Snippet hinzufügen Login Registrieren
Snippets in der Datenbank: 1549 | Anzahl registrierter User: 1833 | Besucher online: 1509
Hauptmenü
Home
Top Ten
Zufälliger Snippet
FAQs
.NET Community
dotnet-forum.de
dotnet-kicks.de
Social

RSS Feeds
Rss Alle Snippets
Rss C#
Rss VB.NET
Rss C++
Rss ASP.NET
Partner
Member of Microsoft Community Leader/Insider Program (CLIP)

WaterBox


Autor: v.wochnik
Sprache: C#
Bewertung:
8.52 (6 votes)
Anzahl der Aufrufe: 9896
  
Kick it on dotnet-kicks.de  

Beschreibung:

Dieses Control stellt eine Art isometrisches Aquarium dar, dessen Wasserspiegel man prozentual bestimmen kann. Des Weiteren ist es möglich, die Farbe des Wassers und Beckens zu bestimmen.
Eine Skala ist auch eingebettet.
Der Code ist vollständig dokumentiert und Properties sind mit Beschreibungen versehen.


Abgelegt unter: Water, Box, WaterBox, Control, Aquarium, Iso, Isometric, isometrisch.



C#
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace ViperBytes.Windows.Forms
{
    /// <summary>
    /// An isometrix box filled with colored water
    /// You can change the height in %.
    /// 
    /// (c) Copyright Vincent Wochnik 2007
    /// </summary>
    class WaterBox : Control
    {
        #region private fields
        /// <summary>
        /// Specifyes the border color
        /// </summary>
        private Color borderColor = Color.DimGray;

        /// <summary>
        /// Specifyes border width
        /// </summary>
        private float borderWidth = 1;

        /// <summary>
        /// Specifyes light fill color
        /// </summary>
        private Color lightFillColor = Color.FromArgb(224, 90, 150, 200);

        /// <summary>
        /// Specifyes dark fill color
        /// </summary>
        private Color darkFillColor = Color.FromArgb(224, 50, 110, 160);

        /// <summary>
        /// Specifyes light background color
        /// </summary>
        private Color lightBackColor = Color.FromArgb(127, 193, 236, 250);

        /// <summary>
        /// Specifyes dark background color
        /// </summary>
        private Color darkBackColor = Color.FromArgb(127, 153, 196, 210);

        /// <summary>
        /// Specifyes, wheather a top is drawn
        /// </summary>
        private bool drawTop = false;

        /// <summary>
        /// Specifyes scala separators
        /// </summary>
        private int separators = 5;

        /// <summary>
        /// The width of separator from 0 to 100 percent
        /// </summary>
        private int separatorWidth = 15;

        /// <summary>
        /// Specifyes the value
        /// </summary>
        private int value = 0;
        #endregion

        #region properties
        /// <summary>
        /// Border color
        /// </summary>
        [Browsable(true)]
        [Category("Appearance")]
        [Description("The color of the box's border")]
        [DefaultValue(typeof(Color), "DimGray")]
        public Color BorderColor
        {
            get
            {
                return this.borderColor;
            }
            set
            {
                if (this.borderColor != value)
                {
                    this.borderColor = value;
                    Invalidate();
                    OnBorderColorChanged(EventArgs.Empty);
                }
            }
        }

        /// <summary>
        /// Border width
        /// </summary>
        [Browsable(true)]
        [Category("Appearance")]
        [Description("Thickness of box's border")]
        [DefaultValue(1)]
        public float BorderWidth
        {
            get
            {
                return this.borderWidth;
            }
            set
            {
                if (this.borderWidth != value)
                {
                    this.borderWidth = value;
                    Invalidate();
                    OnBorderWidthChanged(EventArgs.Empty);
                }
            }
        }

        /// <summary>
        /// Light fill color
        /// </summary>
        [Browsable(true)]
        [Category("Appearance")]
        [Description("The light fill color of water")]
        public Color LightFillColor
        {
            get
            {
                return this.lightFillColor;
            }
            set
            {
                if (this.lightFillColor != value)
                {
                    this.lightFillColor = value;
                    Invalidate();
                    OnLightFillColorChanged(EventArgs.Empty);
                }
            }
        }

        /// <summary>
        /// Dark fill color
        /// </summary>
        [Browsable(true)]
        [Category("Appearance")]
        [Description("The dark fill color of water")]
        public Color DarkFillColor
        {
            get
            {
                return this.darkFillColor;
            }
            set
            {
                if (this.darkFillColor != value)
                {
                    this.darkFillColor = value;
                    Invalidate();
                    OnDarkFillColorChanged(EventArgs.Empty);
                }
            }
        }

        /// <summary>
        /// Light background color
        /// </summary>
        [Browsable(true)]
        [Category("Appearance")]
        [Description("The light fill color of the box's wall")]
        public Color LightBackColor
        {
            get
            {
                return this.lightBackColor;
            }
            set
            {
                if (this.lightBackColor != value)
                {
                    this.lightBackColor = value;
                    Invalidate();
                    OnLightBackColorChanged(EventArgs.Empty);
                }
            }
        }

        /// <summary>
        /// Dark background color
        /// </summary>
        [Browsable(true)]
        [Category("Appearance")]
        [Description("The dark fill color of the box*s wall")]
        public Color DarkBackColor
        {
            get
            {
                return this.darkBackColor;
            }
            set
            {
                if (this.darkBackColor != value)
                {
                    this.darkBackColor = value;
                    Invalidate();
                    OnDarkBackColorChanged(EventArgs.Empty);
                }
            }
        }

        /// <summary>
        /// Draw top
        /// </summary>
        [Browsable(true)]
        [Category("Behavior")]
        [DefaultValue(false)]
        [Description("Specifyes, wheather a top is drawn")]
        public bool DrawTop
        {
            get
            {
                return this.drawTop;
            }
            set
            {
                if (this.drawTop != value)
                {
                    this.drawTop = value;
                    Invalidate();
                    OnDrawTopChanged(EventArgs.Empty);
                }
            }
        }

        /// <summary>
        /// Separators
        /// </summary>
        [Browsable(true)]
        [Category("Behavior")]
        [DefaultValue(5)]
        [Description("The number of separators")]
        public int Separators
        {
            get
            {
                return this.separators;
            }
            set
            {
                if (this.separators != value)
                {
                    this.separators = value;
                    Invalidate();
                    OnSeparatorsChanged(EventArgs.Empty);
                }
            }
        }

        /// <summary>
        /// Specifyes separator width
        /// </summary>
        [Browsable(true)]
        [Category("Behavior")]
        [DefaultValue(15)]
        [Description("The percentual width of separators")]
        public int SeparatorWidth
        {
            get
            {
                return this.separatorWidth;
            }
            set
            {
                if (this.separatorWidth != value)
                {
                    this.separatorWidth = value;
                    Invalidate();
                    OnSeparatorWidthChanged(EventArgs.Empty);
                }
            }
        }

        /// <summary>
        /// The drawn value
        /// </summary>
        [Browsable(true)]
        [Category("Behavior")]
        [DefaultValue(0)]
        [Description("A percentual value")]
        public int Value
        {
            get
            {
                return this.value;
            }
            set
            {
                if (this.value != value)
                {
                    this.value = value;
                    Invalidate();
                    OnValueChanged(EventArgs.Empty);
                }
            }
        }

        /// <summary>
        /// mix between light and dark fill colors
        /// </summary>
        [Browsable(false)]
        [Category("Appearance")]
        [Description("The average between light and dark fill color")]
        public Color MainFillColor
        {
            get
            {
                return Color.FromArgb(
                    (int)((double)(LightFillColor.A + DarkFillColor.A) / 2.0),
                    (int)((double)(LightFillColor.R + DarkFillColor.R) / 2.0),
                    (int)((double)(LightFillColor.G + DarkFillColor.G) / 2.0),
                    (int)((double)(LightFillColor.B + DarkFillColor.B) / 2.0));
            }
        }

        /// <summary>
        /// mix between light and dark background colors
        /// </summary>
        [Browsable(false)]
        [Category("Appearance")]
        [Description("The average between light and dark background color")]
        public Color MainBackColor
        {
            get
            {
                return Color.FromArgb(
                    (int)((double)(LightBackColor.A + DarkBackColor.A) / 2.0),
                    (int)((double)(LightBackColor.R + DarkBackColor.R) / 2.0),
                    (int)((double)(LightBackColor.G + DarkBackColor.G) / 2.0),
                    (int)((double)(LightBackColor.B + DarkBackColor.B) / 2.0));
            }
        }
        #endregion

        #region public events
        /// <summary>
        /// Fired when border color changed
        /// </summary>
        public event EventHandler BorderColorChanged;

        /// <summary>
        /// Fired when border width changed
        /// </summary>
        public event EventHandler BorderWidthChanged;

        /// <summary>
        /// Fired when light fill color changed
        /// </summary>
        public event EventHandler LightFillColorChanged;

        /// <summary>
        /// Fired when dark fill color changed
        /// </summary>
        public event EventHandler DarkFillColorChanged;

        /// <summary>
        /// Fired when light background color changed
        /// </summary>
        public event EventHandler LightBackColorChanged;

        /// <summary>
        /// Fired when dark background color changed
        /// </summary>
        public event EventHandler DarkBackColorChanged;

        /// <summary>
        /// Fired when draw top boolean changed
        /// </summary>
        public event EventHandler DrawTopChanged;

        /// <summary>
        /// Fired when number of separators changed
        /// </summary>
        public event EventHandler SeparatorsChanged;

        /// <summary>
        /// Fired when width of separator changed
        /// </summary>
        public event EventHandler SeparatorWidthChanged;

        /// <summary>
        /// Fired when value changed
        /// </summary>
        public event EventHandler ValueChanged;
        #endregion

        #region constructor
        /// <summary>
        /// Constructor
        /// </summary>
        public WaterBox()
        {
            DoubleBuffered = true;
            Size = new Size(100, 140);
        }
        #endregion

        #region public methods
        /// <summary>
        /// Resets light fill color
        /// </summary>
        public void ResetLightFillColor()
        {
            LightFillColor = Color.FromArgb(224, 90, 150, 200);
        }

        /// <summary>
        /// Serialize light fill color
        /// </summary>
        /// <returns>Wheather a serialization is needed</returns>
        public bool ShouldSerializeLightFillColor()
        {
            return LightFillColor != Color.FromArgb(224, 90, 150, 200);
        }

        /// <summary>
        /// Resets dark fill color
        /// </summary>
        public void ResetDarkFillColor()
        {
            DarkFillColor = Color.FromArgb(224, 50, 110, 160);
        }

        /// <summary>
        /// Serialize dark fill color
        /// </summary>
        /// <returns>Wheather a serialization is needed</returns>
        public bool ShouldSerializeDarkFillColor()
        {
            return DarkFillColor != Color.FromArgb(224, 50, 110, 160);
        }

        /// <summary>
        /// Resets light background color
        /// </summary>
        public void ResetLightBackColor()
        {
            LightBackColor = Color.FromArgb(127, 193, 236, 250);
        }

        /// <summary>
        /// Serialize light background color
        /// </summary>
        /// <returns>Wheather a serialization is needed</returns>
        public bool ShouldSerializeLightBackColor()
        {
            return LightBackColor != Color.FromArgb(127, 193, 236, 250);
        }

        /// <summary>
        /// Resets dark background color
        /// </summary>
        public void ResetDarkBackColor()
        {
            DarkBackColor = Color.FromArgb(127, 153, 196, 210);
        }

        /// <summary>
        /// Serialize dark background color
        /// </summary>
        /// <returns>Wheather a serialization is needed</returns>
        public bool ShouldSerializeDarkBackColor()
        {
            return DarkBackColor != Color.FromArgb(127, 153, 196, 210);
        }
        #endregion

        #region protected methods
        /// <summary>
        /// Fired when border color changed
        /// </summary>
        /// <param name="e">Event arguments</param>
        protected void OnBorderColorChanged(EventArgs e)
        {
            if (BorderColorChanged != null)
                BorderColorChanged(this, e);
        }

        /// <summary>
        /// Fired when border width changed
        /// </summary>
        /// <param name="e">Event arguments</param>
        protected void OnBorderWidthChanged(EventArgs e)
        {
            if (BorderWidthChanged != null)
                BorderWidthChanged(this, e);
        }

        /// <summary>
        /// Fired when light fill color changed
        /// </summary>
        /// <param name="e">Event arguments</param>
        protected void OnLightFillColorChanged(EventArgs e)
        {
            if (LightFillColorChanged != null)
                LightFillColorChanged(this, e);
        }

        /// <summary>
        /// Fired when dark fill color changed
        /// </summary>
        /// <param name="e">Event arguments</param>
        protected void OnDarkFillColorChanged(EventArgs e)
        {
            if (DarkFillColorChanged != null)
                DarkFillColorChanged(this, e);
        }

        /// <summary>
        /// Fired when light background color changed
        /// </summary>
        /// <param name="e">Event arguments</param>
        protected void OnLightBackColorChanged(EventArgs e)
        {
            if (LightBackColorChanged != null)
                LightBackColorChanged(this, e);
        }

        /// <summary>
        /// Fired when dark background color changed
        /// </summary>
        /// <param name="e">Event arguments</param>
        protected void OnDarkBackColorChanged(EventArgs e)
        {
            if (DarkBackColorChanged != null)
                DarkBackColorChanged(this, e);
        }

        /// <summary>
        /// Fired when draw top boolean changed
        /// </summary>
        /// <param name="e">Event arguments</param>
        protected void OnDrawTopChanged(EventArgs e)
        {
            if (DrawTopChanged != null)
                DrawTopChanged(this, e);
        }

        /// <summary>
        /// Fired when number of separators changed
        /// </summary>
        /// <param name="e">Event arguments</param>
        protected void OnSeparatorsChanged(EventArgs e)
        {
            if (SeparatorsChanged != null)
                SeparatorsChanged(this, e);
        }

        /// <summary>
        /// Fired when percentual separator width changed
        /// </summary>
        /// <param name="e">Event arguments</param>
        protected void OnSeparatorWidthChanged(EventArgs e)
        {
            if (SeparatorWidthChanged != null)
                SeparatorWidthChanged(this, e);
        }

        /// <summary>
        /// Fired when value changed
        /// </summary>
        /// <param name="e">Event arguments</param>
        protected void OnValueChanged(EventArgs e)
        {
            if (ValueChanged != null)
                ValueChanged(this, e);
        }

        /// <summary>
        /// Fired on re-paint
        /// </summary>
        /// <param name="e">Event arguments</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            g.SmoothingMode = SmoothingMode.HighQuality;

            // all containing rectangle
            RectangleF rect = new RectangleF(BorderWidth / 2F, BorderWidth / 2F, Width - BorderWidth - 1, Height - BorderWidth - 1);

            // isometric size of the box
            SizeF size = new SizeF(rect.Width, rect.Width / 2F);

            #region draw bottom rectangle
            {
                // the isometric area containing the rhombus
                RectangleF area = new RectangleF(
                    rect.X, rect.Y + rect.Height - size.Height,
                    size.Width, size.Height);

                // the path containing figure of rhombus
                GraphicsPath path = new GraphicsPath();
                path.AddLine(
                    area.X, area.Y + area.Height / 2F,
                    area.X + area.Width / 2F, area.Y);
                path.AddLine(
                    area.X + area.Width, area.Y + area.Height / 2F,
                    area.X + area.Width / 2F, area.Y + area.Height);
                path.CloseFigure();

                // draw path
                g.FillPath(new SolidBrush(MainBackColor), path);
                g.DrawPath(new Pen(BorderColor, BorderWidth), path);
            }
            #endregion
            #region draw bottom wall
            {
                // the isometric background box wall
                // the area is hall, then rect
                GraphicsPath path = new GraphicsPath();
                path.AddLine(
                    rect.X, rect.Y + size.Height / 2F,
                    rect.X + rect.Width / 2F, rect.Y);
                path.AddLine(
                    rect.X + rect.Width / 2F, rect.Y,
                    rect.X + rect.Width, rect.Y + size.Height / 2F);
                path.AddLine(
                    rect.X + rect.Width, rect.Y + rect.Height - size.Height / 2F,
                    rect.X + rect.Width / 2F, rect.Y + rect.Height - size.Height);
                path.AddLine(
                    rect.X + rect.Width / 2F, rect.Y + rect.Height - size.Height,
                    rect.X, rect.Y + rect.Height - size.Height / 2F);
                path.CloseFigure();

                // draw path, with light and dark background color
                g.SetClip(new RectangleF(rect.X, rect.Y, rect.Width / 2F, rect.Height));
                g.FillPath(new SolidBrush(LightBackColor), path);
                g.SetClip(new RectangleF(rect.X + rect.Width / 2F, rect.Y, rect.Width / 2F, rect.Height));
                g.FillPath(new SolidBrush(DarkBackColor), path);
                g.ResetClip();
                g.DrawPath(new Pen(BorderColor, BorderWidth), path);
            }
            #endregion
            #region draw back line
            // draws background wall's edge line
            g.DrawLine(new Pen(BorderColor, BorderWidth),
                rect.X + rect.Width / 2F, rect.Y,
                rect.X + rect.Width / 2F, rect.Y + rect.Height - size.Height);
            #endregion
            #region draw scala
            // draws scala each 100 / separators percentual step
            if (Separators > 0)
            {
                int step = (int)(100.0 / (double)Separators);

                for (int s = step; s < 100; s += step)
                {
                    // the area
                    RectangleF area = new RectangleF(
                        rect.X, rect.Y + rect.Height - size.Height - (rect.Height - size.Height) * (s / 100F),
                        size.Width, size.Height);

                    // draw only the top edge
                    g.DrawLine(
                        new Pen(BorderColor, BorderWidth),
                        area.X + area.Width / 2F - area.Width / 2F * SeparatorWidth / 100F, area.Y + area.Height / 2F * SeparatorWidth / 100F,
                        area.X + area.Width / 2F, area.Y);
                    g.DrawLine(
                        new Pen(BorderColor, BorderWidth),
                        area.X + area.Width / 2F + area.Width / 2F * SeparatorWidth / 100F, area.Y + area.Height / 2F * SeparatorWidth / 100F,
                        area.X + area.Width / 2F, area.Y);
                }
            }
            #endregion
            #region draw top wall
            // draws the front water's wall
            if (Value > 0)
            {
                // the area
                RectangleF area = new RectangleF(
                    rect.X, rect.Y + rect.Height - size.Height - (rect.Height - size.Height) * (Value / 100F),
                    rect.Width, size.Height + (rect.Height - size.Height) * (Value / 100F));

                // the isometric figure
                GraphicsPath path = new GraphicsPath();
                path.AddLine(
                    area.X, area.Y + size.Height / 2F,
                    area.X + area.Width / 2F, area.Y + size.Height);
                path.AddLine(
                    area.X + area.Width / 2F, area.Y + size.Height,
                    area.X + area.Width, area.Y + size.Height / 2F);
                path.AddLine(
                    area.X + area.Width, area.Y + area.Height - size.Height / 2F,
                    area.X + area.Width / 2F, area.Y + area.Height);
                path.AddLine(
                    area.X + area.Width / 2F, area.Y + area.Height,
                    area.X, area.Y + area.Height - size.Height / 2F);
                path.CloseFigure();

                // draw figure with light and dark water color
                g.SetClip(new RectangleF(rect.X, rect.Y, rect.Width / 2F, rect.Height));
                g.FillPath(new SolidBrush(DarkFillColor), path);
                g.SetClip(new RectangleF(rect.X + rect.Width / 2F, rect.Y, rect.Width / 2F, rect.Height));
                g.FillPath(new SolidBrush(LightFillColor), path);
                g.ResetClip();
                g.DrawPath(new Pen(BorderColor, BorderWidth), path);
            }
            #endregion
            #region draw fill rectangle
            // draws water's top
            if (Value > 0)
            {
                // water's height area
                RectangleF area = new RectangleF(
                    rect.X, rect.Y + rect.Height - size.Height - (rect.Height - size.Height) * (Value / 100F),
                    size.Width, size.Height);

                // isometric figure
                GraphicsPath path = new GraphicsPath();
                path.AddLine(
                    area.X, area.Y + area.Height / 2F,
                    area.X + area.Width / 2F, area.Y);
                path.AddLine(
                    area.X + area.Width, area.Y + area.Height / 2F,
                    area.X + area.Width / 2F, area.Y + area.Height);
                path.CloseFigure();

                // draw figure
                g.FillPath(new SolidBrush(MainFillColor), path);
                g.DrawPath(new Pen(BorderColor, BorderWidth), path);
            }
            #endregion
            #region draw top rectangle
            if (DrawTop)
            {
                // area
                RectangleF area = new RectangleF(
                    rect.X, rect.Y,
                    size.Width, size.Height);

                // isometric figure
                GraphicsPath path = new GraphicsPath();
                path.AddLine(
                    area.X, area.Y + area.Height / 2F,
                    area.X + area.Width / 2F, area.Y);
                path.AddLine(
                    area.X + area.Width, area.Y + area.Height / 2F,
                    area.X + area.Width / 2F, area.Y + area.Height);
                path.CloseFigure();

                // draw figure
                g.FillPath(new SolidBrush(MainBackColor), path);
                g.DrawPath(new Pen(BorderColor, BorderWidth), path);
            }
            #endregion

            base.OnPaint(e);
        }

        /// <summary>
        /// Fired when size changed
        /// </summary>
        /// <param name="e">Event arguments</param>
        protected override void OnSizeChanged(EventArgs e)
        {
            if (Height < (int)Math.Ceiling(Width / 2F))
                Height = (int)Math.Ceiling(Width / 2F);

            base.OnSizeChanged(e);
        }
        #endregion
    }
}

Sie haben Fragen zu diesem Snippet oder brauchen Hilfe bei der .NET Entwicklung?
Freundliche und kompetente Entwickler helfen Ihnen gern weiter im Forum für .NET Entwicklung.



Kommentare:
(Zum Schreiben von Kommentaren bitte anmelden.)

codecom schrieb am:  25.12.2007 09:28:02

Echt scharfes teil, vorallem die Isometrie und Transparenz.
Ralf Kronen schrieb am:  22.01.2008 04:30:05

weiß jemand wie ich diesen code in ein projekt einbaue und dann das control verwende? Bin neu im programmieren :-)
Jan Welker schrieb am:  22.01.2008 08:05:24

Hallo,
am Besten Du fügst Deiner Projektmappe eine neue Klassendatei hinzu (*.cs). Dort kopierst du den Code hin nein.
Dann kannst Du in Deinem Programm die Waterbox zum Beispiel so auf deiner Oberfläche hinzufügen:

ViperBytes.Windows.Forms.WaterBox waterbox = new WaterBox();
this.Controls.Add(waterbox);
waterbox.Height = 200;
waterbox.Width = 150;
waterbox.Value = 33;

Jan
Niklas schrieb am:  29.07.2010 20:04:53

Oder du machst eine neue Klassenbibliothek und fügst die DLL nach dem Erstellen als neuen Steuerelement in die Toolbox ein.


Diese Snippets könnten für Sie interessant sein:
[C#] InputBox WPF C#
[C#] Doppelbufferung für Steuerelemente aktivieren
[C#] Transparenter Hintergrund beim Steuerelement
[C#] CursorChanger
[ASP.net] NullReferenceException
[VB.NET] ControlResize wie in der IDE auch zur Laufzeit
[C#] Generischer Invoker für Windows Form Controls
[ASP.net] Formularelement fokusieren auf Ajax Seiten
[C#] Threadsichere und generische Kommunikation Windows Forms
[C#] Events aus Worker-Thread im GUI-Thread werfen! Kein Invoke!
[C#] Controls gleichen Typs von einem Container in Winform holen
[C#] Eigenschaften aller Steuerlemente eines Formulars setzen
[VB.NET] Alle Textboxen zurücksetzen
[ASP.net] bestimmtes Control auf der aspx-Seite finden
[VB.NET] Oft benötigte Properties von Controls schnell zentral ausfüh
[VB.NET] Das Klick-Event von Controls gemeinsam auffangen und zentral
[VB.NET] Linien u. Kreise a la VB6 - Einfach Zeichnen
[C#] iTunes-ProgressBar
[VB.NET] Alle Controls einer Form Enablen/Disablen
[C#] Löschen aller TextControls auf einer Form in C#
[VB.NET] Control Resize wie in der IDE auch zur Laufzeit - Extended
[VB.NET] List all controls by using the name of the controls
[C#] Custom Toolstrip Renderer
[C#] Prüfen ob in einem Verzeichnis Schreibrechte verfügbar sind!
[C#] Hochwertige (optisch ansprechende) WPF - Buttons
[C#] WPF - Buttons "OK/Cancel" - endlich unverwechselbar -
[C#] Visuelles Feedback fokussierter Text Boxen
[C#] ISO-Abbild von einer CD/DVD erstellen

schlecht sehr gut
1 2 3 4 5 6 7 8 9 10
Nur angemeldete User können Snippets bewerten.