Darken or Lighten an area of a form...

  • Thread starter Thread starter Rlrcstr
  • Start date Start date
R

Rlrcstr

Is there a way to darken or lighten an area of a form or control via the
graphics object? I'm using an ownerdraw listbox and I want to have a small
area of the item be a bit lighter than the rest of the object, but I want
the user to be able to set the main color. I've read up on the fact that we
don't have any raster ops in GDI+, but I was hoping there might be an y easy
way to do this. Thanks.

Jerry
 
Hi maybe this can help you:

put a listbox on a form and copy paste this code:

Private Sub lstPeter_DrawItem(ByVal sender As System.Object, ByVal e As _
System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
'e.Graphics.FillRectangle(New
System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, _ 'Color.LightGray,
Color.Gray, Drawing2D.LinearGradientMode.BackwardDiagonal), e.Bounds)
e.Graphics.FillRectangle(Brushes.LightGray, e.Bounds.X, e.Bounds.Y,
CInt(e.Bounds.Width / 2), CInt _(e.Bounds.Height))
e.Graphics.FillRectangle(Brushes.DarkGray, e.Bounds.X +
CInt(e.Bounds.Width / 2), e.Bounds.Y, CInt _(e.Bounds.Width / 2),
CInt(e.Bounds.Height))
e.Graphics.DrawString(CStr(ListBox1.Items(e.Index)), ListBox1.Font,
Brushes.White, e.Bounds.X, _ e.Bounds.Y)
e.DrawFocusRectangle()
End Sub

Private Sub frm3_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
ListBox1.DrawMode = DrawMode.OwnerDrawFixed
ListBox1.Items.Add("Hello")
ListBox1.Items.Add("World")
End Sub

greetz Peter
 
Thanks for the reply, but that's not really what I'm looking for.

I have an ownerdraw listbox that I'm displaying info in 3 columns. I want
the user to specify the backcolor for alternating rows. This is all easy.
I can draw everything without an issue.

I wanted to give the alternating columns a slightly darker shade of the
background color on each line. Since my last post, I've implemented this
via creating a new brush from the old and subtracting 15 from each of the
color elements of the pen color. Color.FromARGB()

This works. But I was originally wondering if there was some operation that
would just let me paint a darkening effect on the background so I didn't
have to worry about what color was there originally.

Thanks.

Jerry
 
You could overprint a transparent black. Use Color.FromArgb to create a
brush with a transparent black colour.

You may also be interested in the article on using HSB which can be found in
the GDI+ FAQ.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Very cool stuff. Thanks!

I posted in the controls group regarding display issues trying to use the
listbox as a control container. Any insight on that?

Jerry
 
Hi,

Jerry said:
I wanted to give the alternating columns a slightly darker shade of the
background color on each line. Since my last post, I've implemented this
via creating a new brush from the old and subtracting 15 from each of the
color elements of the pen color. Color.FromARGB()

This works. But I was originally wondering if there was some operation that
would just let me paint a darkening effect on the background so I didn't
have to worry about what color was there originally.

in addition to Bob's GDI+-FAQ, check out Steve's color-pack (pretty much
ready to use):
www.vbaccelerator.com/home/NET/Code/Libraries/Graphics/HLS_to_RGB/article.asp

Cheers,
Olaf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top