Click here to Skip to main content
16,006,768 members
Home / Discussions / C#
   

C#

 
GeneralRe: Get image property Pin
Alex Korchemniy8-Oct-04 5:01
Alex Korchemniy8-Oct-04 5:01 
GeneralRe: Get image property Pin
codes/w8-Oct-04 19:08
codes/w8-Oct-04 19:08 
GeneralGraphics Color triangle Pin
new_eng_078-Oct-04 1:37
new_eng_078-Oct-04 1:37 
GeneralRe: Graphics Color triangle Pin
benjymous8-Oct-04 2:08
benjymous8-Oct-04 2:08 
GeneralRe: Graphics Color triangle Pin
new_eng_078-Oct-04 2:22
new_eng_078-Oct-04 2:22 
GeneralRe: Graphics Color triangle Pin
benjymous8-Oct-04 2:34
benjymous8-Oct-04 2:34 
GeneralRe: Graphics Color triangle Pin
Heath Stewart8-Oct-04 7:06
protectorHeath Stewart8-Oct-04 7:06 
GeneralRe: Graphics Color triangle Pin
Heath Stewart8-Oct-04 7:45
protectorHeath Stewart8-Oct-04 7:45 
Take a look at the PathGradientBrush, the GraphicsPath, and related classes and structs. If I understand your question right, the sample below should work for you by encapsulating your triangle into a separate control (with a clipping region set to the triangle for your control as well).
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
 
class Test : Form
{
  static void Main()
  {
    Application.Run(new Test());
  }
 
  Test()
  {
    Text = "Triangle Example";
 
    Triangle t = new Triangle();
    Controls.Add(t);
    t.Dock = DockStyle.Fill;
  }
}
 
class Triangle : Control
{
  public Triangle()
  {
    SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint
      | ControlStyles.DoubleBuffer | ControlStyles.ResizeRedraw, true);
 
    UpdatePath();
  }
 
  protected override void OnPaint(PaintEventArgs e)
  {
    base.OnPaint(e);
 
    if (!init)
    {
      UpdateBrush();
      init = true;
    }
 
    Graphics g = e.Graphics;
    g.Clip = region;
    g.FillPath(brush, path);
  }
 
  protected override void OnResize(EventArgs e)
  {
    base.OnResize(e);
    UpdatePath();
  }
 
  protected override void Dispose(bool disposing)
  {
    if (disposing)
    {
      if (path != null) path.Dispose();
      if (region != null) region.Dispose();
      if (brush != null) brush.Dispose();
    }
  }
 
  GraphicsPath path;
  Region region;
  void UpdatePath()
  {
    PointF p1 = new PointF(Width / 2, Top);
    PointF p2 = new PointF(0, Bottom);
    PointF p3 = new PointF(Width, Bottom);
 
    if (path != null)
    {
      path.Dispose();
      path = null;
    }
 
    if (region != null)
    {
      region.Dispose();
      region = null;
    }
 
    path = new GraphicsPath();
    path.AddPolygon(new PointF[] {p1, p2, p3});
    region = new Region(path);
 
    if (init) UpdateBrush();
  }
 
  PathGradientBrush brush;
  bool init = false;
  void UpdateBrush()
  {
    if (brush != null)
    {
      brush.Dispose();
      brush = null;
    }
 
    brush = new PathGradientBrush(path);
    brush.CenterColor = Color.Gray;
    brush.SurroundColors = new Color[] {c1, c2, c3};
  }
 
  Color c1 = Color.Red, c2 = Color.Green, c3 = Color.Blue;
  public Color C1
  {
    get { return c1; }
    set { c1 = value; UpdateBrush(); }
  }
 
  public Color C2
  {
    get { return c2; }
    set { c2 = value; UpdateBrush(); }
  }
 
  public Color C3
  {
    get { return c3; }
    set { c3 = value; UpdateBrush(); }
  }
}


This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles]
Generaltab page - tab pane Pin
pat2708818-Oct-04 1:15
pat2708818-Oct-04 1:15 
GeneralRe: tab page - tab pane Pin
Heath Stewart8-Oct-04 6:23
protectorHeath Stewart8-Oct-04 6:23 
GeneralRe: tab page - tab pane Pin
pat27088111-Oct-04 11:13
pat27088111-Oct-04 11:13 
Generalhttps server Pin
ppp0018-Oct-04 0:54
ppp0018-Oct-04 0:54 
GeneralRe: https server Pin
Colin Angus Mackay8-Oct-04 1:09
Colin Angus Mackay8-Oct-04 1:09 
GeneralRe: https server Pin
Vasudevan Deepak Kumar8-Oct-04 3:49
Vasudevan Deepak Kumar8-Oct-04 3:49 
Generalxml with c# for pocketpc Pin
pujas8-Oct-04 0:47
pujas8-Oct-04 0:47 
GeneralRe: xml with c# for pocketpc Pin
Heath Stewart8-Oct-04 6:20
protectorHeath Stewart8-Oct-04 6:20 
Generalxml with c# for pocketpc Pin
pujas8-Oct-04 0:47
pujas8-Oct-04 0:47 
QuestionHow can I get a *real* destructor?! Pin
nurglitch8-Oct-04 0:36
nurglitch8-Oct-04 0:36 
AnswerRe: How can I get a *real* destructor?! Pin
sreejith ss nair8-Oct-04 1:51
sreejith ss nair8-Oct-04 1:51 
GeneralRe: How can I get a *real* destructor?! Pin
nurglitch8-Oct-04 2:15
nurglitch8-Oct-04 2:15 
GeneralRe: How can I get a *real* destructor?! Pin
Colin Angus Mackay8-Oct-04 3:17
Colin Angus Mackay8-Oct-04 3:17 
GeneralRe: How can I get a *real* destructor?! Pin
Matt Gerrans8-Oct-04 9:32
Matt Gerrans8-Oct-04 9:32 
GeneralSafeNativeMethods Pin
Mikke_x8-Oct-04 0:08
Mikke_x8-Oct-04 0:08 
QuestionHow to add an active directory user to One BuiltIn Group- programmatically Pin
Subin KJ7-Oct-04 23:31
Subin KJ7-Oct-04 23:31 
GeneralPassing variables by ref Pin
Peter Beedell7-Oct-04 22:28
Peter Beedell7-Oct-04 22:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.