|
-
Feb 20th, 2012, 08:41 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Pen DashPattern - alternating colours?
Can I create a Pen dashpattern that consists of alternating colours rather than a solid colour followed by a space? For example:
LinePen.DashPattern = New Single() {6, 4}
... creates a pattern with a dash of 6 pixels followed by a space of 4 pixels. Rather than a space, I would like a different solid colour. That way I could create a rectangular cursor with something like a black/white alternating pattern, which would be clearly visible on top of any picture.
Thanks.
-
Feb 20th, 2012, 09:49 AM
#2
Re: Pen DashPattern - alternating colours?
The simplest way to do that is by drawing the cursor twice, with two pens, each with a different Color, DashPattern and DashOffset.
An alternative way would be to make an image containing two dashes of the alternating colors. Then convert that to a TextureBrush, and convert that to a Pen like this:
Code:
Dim pn As New Pen(textureBrush)
It takes a few more steps, but it is obviously far more flexible because you could use any image.
BB
-
Feb 20th, 2012, 09:57 AM
#3
Thread Starter
Fanatic Member
Re: Pen DashPattern - alternating colours?
 Originally Posted by boops boops
The simplest way to do that is by drawing the cursor twice, with two pens, each with a different Color, DashPattern and DashOffset.
An alternative way would be to make an image containing two dashes of the alternating colors. Then convert that to a TextureBrush, and convert that to a Pen like this:
Code:
Dim pn As New Pen(textureBrush)
It takes a few more steps, but it is obviously far more flexible because you could use any image.
BB
The TextureBrush sounds like a good idea. I already have quite a lot drawing in my cursor routine so I would rather not have to double everything.
BTW, I sent you a PM a couple of weeks ago. Perhaps you didn't get it? I had a query about your FastPix routine. I can't remember exactly what the query was now! I think it was something to do with using the byte array data - it didn't seem to be working properly. I think I just changed to GetPixel and SetPixel (which I use a lot) and it was fine.
Thanks, as always, for your help.
Last edited by paulg4ije; Feb 20th, 2012 at 10:02 AM.
-
Feb 20th, 2012, 10:08 AM
#4
Re: Pen DashPattern - alternating colours?
 Originally Posted by paulg4ije
BTW, I sent you a PM a couple of week ago. Perhaps you didn't get it? I had a query about your FastPix routine. I can't remember exactly what the query was now! I think it was something to do with using the byte array data - it didn't seem to be working properly. I think I just changed to GetPixel and SetPixel (which I use a lot) and it was fine.
Thanks, as always, for your help.
Sorry, it's been a frantic period lately. I would have been more inclined to help you if you had posted your question to the FastPix thread in the code bank. Sometimes posting stuff there is like talking to yourself .
BB
-
Feb 20th, 2012, 10:12 AM
#5
Thread Starter
Fanatic Member
Re: Pen DashPattern - alternating colours?
 Originally Posted by boops boops
Sorry, it's been a frantic period lately. I would have been more inclined to help you if you had posted your question to the FastPix thread in the code bank. Sometimes posting stuff there is like talking to yourself  .
BB
No problem. I use FastPix a lot and it has been very helpful.
Many thanks
-
Feb 20th, 2012, 10:48 AM
#6
Re: Pen DashPattern - alternating colours?
I just had a thought: the dashes won't work very well using the TextureBrush method, because they won't follow the direction of the line. The TextureBrush just "shows through" the line of the pen so vertical lines would have a solid color, either black or white. You could make some kind of checkerboard pattern to use as the image instead of the two dashes, but I expect using two pens will look better. It won't be any less efficient. If your cursor is more elaborate than just a rectangle, you could build it as a GraphicsPath and draw that instead of drawing parts individually. BB
-
Feb 20th, 2012, 10:54 AM
#7
Thread Starter
Fanatic Member
Re: Pen DashPattern - alternating colours?
 Originally Posted by boops boops
I just had a thought: the dashes won't work very well using the TextureBrush method, because they won't follow the direction of the line. The TextureBrush just "shows through" the line of the pen so vertical lines would have a solid color, either black or white. You could make some kind of checkerboard pattern to use as the image instead of the two dashes, but I expect using two pens will look better. It won't be any less efficient. If your cursor is more elaborate than just a rectangle, you could build it as a GraphicsPath and draw that instead of drawing parts individually. BB
Yeah, I've just tried a checkerboard pattern and it's not bad, but not quite right. The effect depends on exactly where the cursor is placed. I will look at using two pens and drawing the rectangle twice.
Thanks again.
-
Feb 20th, 2012, 11:12 AM
#8
Thread Starter
Fanatic Member
Re: Pen DashPattern - alternating colours?
The two pen idea works well. I used this pattern:
LinePen(1).DashPattern = New Single() {6, 6}
LinePen(2).DashPattern = New Single() {1, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6}
This gives a near-perfect dashed line. There may be a better way but this works for me 
Thanks Boops ...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|