473,785 Members | 2,969 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Darken or Lighten an area of a form...

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
Nov 21 '05 #1
5 2593
Hi maybe this can help you:

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

Private Sub lstPeter_DrawIt em(ByVal sender As System.Object, ByVal e As _
System.Windows. Forms.DrawItemE ventArgs) Handles ListBox1.DrawIt em
'e.Graphics.Fil lRectangle(New
System.Drawing. Drawing2D.Linea rGradientBrush( e.Bounds, _ 'Color.LightGra y,
Color.Gray, Drawing2D.Linea rGradientMode.B ackwardDiagonal ), e.Bounds)
e.Graphics.Fill Rectangle(Brush es.LightGray, e.Bounds.X, e.Bounds.Y,
CInt(e.Bounds.W idth / 2), CInt _(e.Bounds.Heig ht))
e.Graphics.Fill Rectangle(Brush es.DarkGray, e.Bounds.X +
CInt(e.Bounds.W idth / 2), e.Bounds.Y, CInt _(e.Bounds.Widt h / 2),
CInt(e.Bounds.H eight))
e.Graphics.Draw String(CStr(Lis tBox1.Items(e.I ndex)), ListBox1.Font,
Brushes.White, e.Bounds.X, _ e.Bounds.Y)
e.DrawFocusRect angle()
End Sub

Private Sub frm3_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
ListBox1.DrawMo de = DrawMode.OwnerD rawFixed
ListBox1.Items. Add("Hello")
ListBox1.Items. Add("World")
End Sub

greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.
"Rlrcstr" <rl*****@msn.co m> schreef in bericht
news:Oq******** ******@TK2MSFTN GP09.phx.gbl...
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

Nov 21 '05 #2
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

"Peter Proost" <pp*****@nospam .hotmail.com> wrote in message
news:eF******** ******@TK2MSFTN GP10.phx.gbl...
Hi maybe this can help you:

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

Private Sub lstPeter_DrawIt em(ByVal sender As System.Object, ByVal e As _
System.Windows. Forms.DrawItemE ventArgs) Handles ListBox1.DrawIt em
'e.Graphics.Fil lRectangle(New
System.Drawing. Drawing2D.Linea rGradientBrush( e.Bounds, _ 'Color.LightGra y,
Color.Gray, Drawing2D.Linea rGradientMode.B ackwardDiagonal ), e.Bounds)
e.Graphics.Fill Rectangle(Brush es.LightGray, e.Bounds.X, e.Bounds.Y, CInt(e.Bounds.W idth / 2), CInt _(e.Bounds.Heig ht))
e.Graphics.Fill Rectangle(Brush es.DarkGray, e.Bounds.X +
CInt(e.Bounds.W idth / 2), e.Bounds.Y, CInt _(e.Bounds.Widt h / 2),
CInt(e.Bounds.H eight))
e.Graphics.Draw String(CStr(Lis tBox1.Items(e.I ndex)), ListBox1.Font, Brushes.White, e.Bounds.X, _ e.Bounds.Y)
e.DrawFocusRect angle()
End Sub

Private Sub frm3_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
ListBox1.DrawMo de = DrawMode.OwnerD rawFixed
ListBox1.Items. Add("Hello")
ListBox1.Items. Add("World")
End Sub

greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.
"Rlrcstr" <rl*****@msn.co m> schreef in bericht
news:Oq******** ******@TK2MSFTN GP09.phx.gbl...
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


Nov 21 '05 #3
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.

"Jerry Camel" <rl*****@msn.co m> wrote in message
news:eR******** ******@TK2MSFTN GP15.phx.gbl...
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

"Peter Proost" <pp*****@nospam .hotmail.com> wrote in message
news:eF******** ******@TK2MSFTN GP10.phx.gbl...
Hi maybe this can help you:

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

Private Sub lstPeter_DrawIt em(ByVal sender As System.Object, ByVal e As _
System.Windows. Forms.DrawItemE ventArgs) Handles ListBox1.DrawIt em
'e.Graphics.Fil lRectangle(New
System.Drawing. Drawing2D.Linea rGradientBrush( e.Bounds, _
'Color.LightGra y,
Color.Gray, Drawing2D.Linea rGradientMode.B ackwardDiagonal ), e.Bounds)
e.Graphics.Fill Rectangle(Brush es.LightGray, e.Bounds.X,

e.Bounds.Y,
CInt(e.Bounds.W idth / 2), CInt _(e.Bounds.Heig ht))
e.Graphics.Fill Rectangle(Brush es.DarkGray, e.Bounds.X +
CInt(e.Bounds.W idth / 2), e.Bounds.Y, CInt _(e.Bounds.Widt h / 2),
CInt(e.Bounds.H eight))
e.Graphics.Draw String(CStr(Lis tBox1.Items(e.I ndex)),

ListBox1.Font,
Brushes.White, e.Bounds.X, _ e.Bounds.Y)
e.DrawFocusRect angle()
End Sub

Private Sub frm3_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
ListBox1.DrawMo de = DrawMode.OwnerD rawFixed
ListBox1.Items. Add("Hello")
ListBox1.Items. Add("World")
End Sub

greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to
produce
bigger and better idiots. So far, the Universe is winning.
"Rlrcstr" <rl*****@msn.co m> schreef in bericht
news:Oq******** ******@TK2MSFTN GP09.phx.gbl...
> 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
>
>



Nov 21 '05 #4
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

"Bob Powell [MVP]" <bob@_spamkille r_bobpowell.net > wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
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.

"Jerry Camel" <rl*****@msn.co m> wrote in message
news:eR******** ******@TK2MSFTN GP15.phx.gbl...
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

"Peter Proost" <pp*****@nospam .hotmail.com> wrote in message
news:eF******** ******@TK2MSFTN GP10.phx.gbl...
Hi maybe this can help you:

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

Private Sub lstPeter_DrawIt em(ByVal sender As System.Object, ByVal e As _ System.Windows. Forms.DrawItemE ventArgs) Handles ListBox1.DrawIt em
'e.Graphics.Fil lRectangle(New
System.Drawing. Drawing2D.Linea rGradientBrush( e.Bounds, _
'Color.LightGra y,
Color.Gray, Drawing2D.Linea rGradientMode.B ackwardDiagonal ), e.Bounds)
e.Graphics.Fill Rectangle(Brush es.LightGray, e.Bounds.X,

e.Bounds.Y,
CInt(e.Bounds.W idth / 2), CInt _(e.Bounds.Heig ht))
e.Graphics.Fill Rectangle(Brush es.DarkGray, e.Bounds.X +
CInt(e.Bounds.W idth / 2), e.Bounds.Y, CInt _(e.Bounds.Widt h / 2),
CInt(e.Bounds.H eight))
e.Graphics.Draw String(CStr(Lis tBox1.Items(e.I ndex)),

ListBox1.Font,
Brushes.White, e.Bounds.X, _ e.Bounds.Y)
e.DrawFocusRect angle()
End Sub

Private Sub frm3_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
ListBox1.DrawMo de = DrawMode.OwnerD rawFixed
ListBox1.Items. Add("Hello")
ListBox1.Items. Add("World")
End Sub

greetz Peter

--
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to
produce
bigger and better idiots. So far, the Universe is winning.
"Rlrcstr" <rl*****@msn.co m> schreef in bericht
news:Oq******** ******@TK2MSFTN GP09.phx.gbl...
> 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
>
>



Nov 21 '05 #5
Hi,

Jerry Camel wrote:
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):
http://www.vbaccelerator.com/home/NE...GB/article.asp

Cheers,
Olaf
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
6458
by: Cues Plus | last post by:
Hello, I have a simple form text area for people to add comments in. The problem is that using the standard <TEXT AREA NAME="comments" ROWS=4 COLS=35></TEXT AREA> Allows people to put in quotes like: Please ensure "bob" is listed as the first name not "bobby". When that happens, the next processing of the text area input is submitted
7
15973
by: BBB | last post by:
I have a web form with a <div> section ... I have it setup so the Update/Cancel buttons are fixed at the bottom of the screen while the content of the form is in the <div> and scrolls. Nice to the end user ... but when they go to print ... of course they only get a portion of the entire web site. I've searched and found references to CSS type solutions but have been unable to get them to work. <div id="main" style="overflow:auto;">...
2
325
by: Paul Mars | last post by:
How can I get the useable dimensions or coordinates of the working area of a form? All that I can find return the monitor screen area, but I need the usable area inside the open form. Not incl. menu, toolbar, status bar. Dim x As Integer = MdiParent.Height Me.SetDesktopBounds(0, 0, 0, 0)
4
8844
by: Henry Wu | last post by:
Hi, I see examples of Magnifying an area under mouse coordinates to a form or picturebox using VB6 and VC6, does anyone know how to do it under VB.NET? Its nice to use the new GDI+ for it. Thanks, Henry
7
5943
by: Behzad | last post by:
hi all, I'am recently working on an applicatoin.Whenever a user creates a new project in my application the new project's form is displayed.The users are unfamiliar with computer wolrd.I want to focus their attention on what is really working on top of the screen ( say it is a new project form).Now i have decided to darken the background screen and the result would be something like "Shut Down Windows" form in Windows XP/2003.how could...
4
21017
by: devine | last post by:
Hi All, I am VERY new to Javascript. I have been provided with some code, which will enable me to hide/show a text area and change a submit button dependant on a check box. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
2
1844
by: Eric | last post by:
When i bound the other form in my main form. The whole first subform area is covered with white color. But when i bound another form its not shows the whole area in white color. Why my one subform shows the whole area in white color. I mean its nothing shows any thing in that area. But my other form shows all of the fields and labels in that area where i created it. Thanks.
3
4181
by: Harry_Crow | last post by:
I wanted to change the Non client area height. This was not possible in the existing Form TitleBar. So I set the FormBorderStyle= None and I calculated and introduced the Non Client area myself. So the height and width of the Non Client area is 15 and 4 pixels border respectively. Also the Nonclient area has been painted as per our need. Now all is fine but in design time when the controls in the form are anchored other than top, left. Now...
2
3330
by: yomadhu | last post by:
I created a dynamic form in javascript. Am unable to get those values in to php to display. I need all details. If i add 10 rows the i need to display those all values. Can any one help me for that code. <HTML> <HEAD> <TITLE> Add/Remove dynamic rows in HTML table </TITLE> <script type="text/javascript" src="script.js"> // JavaScript Document var c=0;
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10091
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.