how do i change colour of my region?
how do i change colour of my region?
how do i change colour of my region?
how do i change colour of my region?
how do i change colour of my region?
how do i change colour of my region? how do i change colour of my region? how do i change colour of my region? how do i change colour of my region? how do i change colour of my region? how do i change colour of my region? how do i change colour of my region? how do i change colour of my region?
how do i change colour of my region? how do i change colour of my region?
how do i change colour of my region?
Go Back  Xtreme Visual Basic Talk > > > how do i change colour of my region?


Reply
 
Thread Tools Display Modes
  #1  
Old 03-08-2002, 04:04 AM
andreww
Guest
 
Posts: n/a
Default how do i change colour of my region?


i want to know how to change my region from black to a different colour

heres the code:

Private Type COORD
x As Long
y As Long
End Type
Dim mouses As COORD
Dim inside
Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As Any, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
Private Declare Function Polygon Lib "gdi32" (ByVal hdc As Long, lpPoint As Any, ByVal nCount As Long) As Long
Private Declare Function FillRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long
Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function PtInRegion Lib "gdi32" (ByVal hRgn As Long, ByVal x As Long, ByVal y As Long) As Long
Const ALTERNATE = 2
Const WINDING = 4
Const BLACKBRUSH = 4
Dim poly(1 To 3) As COORD, NumCoords As Long, hBrush As Long, hRgn As Long

Private Sub Command1_Click()
NumCoords = 3
Me.ScaleMode = vbPixels
poly(1).x = 100
poly(1).y = 100
poly(2).x = Form1.ScaleWidth / 4 + 100
poly(2).y = 3 * Form1.ScaleHeight / 4 + 100
poly(3).x = 3 * Form1.ScaleWidth / 4 + 100
poly(3).y = 3 * Form1.ScaleHeight / 4 + 100
Polygon Me.hdc, poly(1), NumCoords
hBrush = GetStockObject(BLACKBRUSH)
hRgn = CreatePolygonRgn(poly(1), NumCoords, ALTERNATE)
If hRgn Then FillRgn Me.hdc, hRgn, hBrush
If PtInRegion(hRgn, 1, 1) <> 0 Then Me.Caption = "Inside"
DeleteObject hRgn
End Sub
Reply With Quote
  #2  
Old 03-08-2002, 04:51 PM
Squirm's Avatar
Squirmhow do i change colour of my region? Squirm is offline
Political Coder

Retired Moderator
* Guru *
 
Join Date: Mar 2001
Location: London, England
Posts: 8,037
Default

You could use CreateSolidBrush API to make a solid-colour brush instead of using GetStockObject.
__________________
Search the forums | Use [vb][/vb] tags | Still IRCing
Reply With Quote
  #3  
Old 03-09-2002, 08:05 PM
andreww
Guest
 
Posts: n/a
Default

squirm could you tell me what code to type in as i couldnt get it working
Reply With Quote
  #4  
Old 03-10-2002, 01:10 PM
Squirm's Avatar
Squirmhow do i change colour of my region? Squirm is offline
Political Coder

Retired Moderator
* Guru *
 
Join Date: Mar 2001
Location: London, England
Posts: 8,037
Default

Code:
Option Explicit

Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long

Private Sub Form_Paint()

    'Declare variables
    Dim hBrush As Long      'Used to store the solid brush
    Dim hOldBrush As Long   'Used to store the old brush
    
    'Create brush
    hBrush = CreateSolidBrush(vbRed)
    
    'Select it and store the old brush
    hOldBrush = SelectObject(Me.hdc, hBrush)
    
    'Do your draw commands here on Me.hdc
    'you can use any hDC you want
    
    'Select back the old brush
    hBrush = SelectObject(hOldBrush)
    
    'Delete the solid colour brush
    DeleteObject hBrush
    
End Sub
__________________
Search the forums | Use [vb][/vb] tags | Still IRCing
Reply With Quote
  #5  
Old 03-10-2002, 10:22 PM
andreww
Guest
 
Posts: n/a
Default

There now is a bit of a black border around the coloured region
heres the code.. and attached is a picture of what i mean

Private Type COORD
x As Long
y As Long
End Type
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As Any, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
Private Declare Function Polygon Lib "gdi32" (ByVal hdc As Long, lpPoint As Any, ByVal nCount As Long) As Long
Private Declare Function FillRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function PtInRegion Lib "gdi32" (ByVal hRgn As Long, ByVal x As Long, ByVal y As Long) As Long
Dim poly(1 To 3) As COORD, NumCoords As Long, hBrush As Long, hRgn As Long

Private Sub Command1_Click()
hBrush = CreateSolidBrush(vbRed)
NumCoords = 3
Me.ScaleMode = vbPixels
poly(1).x = 100
poly(1).y = 100
poly(2).x = 200
poly(2).y = 100
poly(3).x = 150
poly(3).y = 200
Polygon Me.hdc, poly(1), NumCoords
hRgn = CreatePolygonRgn(poly(1), NumCoords, ALTERNATE)
If hRgn Then FillRgn Me.hdc, hRgn, hBrush
If PtInRegion(hRgn, 1, 1) <> 0 Then Me.Caption = "Inside"
DeleteObject hRgn
'DeleteObject hBrush
End Sub
Attached Images
File Type: jpg mypic.jpg (8.7 KB, 26 views)
Reply With Quote
  #6  
Old 03-10-2002, 11:16 PM
andreww
Guest
 
Posts: n/a
Default

actually ive just worked that out by changing the forecolor

but is there a way of setting the colour without changing the forecolor?

Last edited by andreww; 03-10-2002 at 11:28 PM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
how do i change colour of my region?
how do i change colour of my region?
how do i change colour of my region? how do i change colour of my region?
how do i change colour of my region?
how do i change colour of my region?
how do i change colour of my region? how do i change colour of my region? how do i change colour of my region? how do i change colour of my region? how do i change colour of my region? how do i change colour of my region? how do i change colour of my region?
how do i change colour of my region?
how do i change colour of my region?
 
how do i change colour of my region?
how do i change colour of my region?
 
-->