PC Review


Reply
Thread Tools Rate Thread

Adding Line Style on Forms (or another way)??

 
 
faisalmooraby.subscription@googlemail.com
Guest
Posts: n/a
 
      26th Oct 2007
Hello Listers

I am looking for a way of adding Line style on a form. Basically, the
user will choose the line width (from combo) and the line width (on
the form) changes accordingly.

This will be used with another programs api (which I have done in the
past) - Mapinfo.

I look forward for your response. If you need more info, please let
me know.

Faisal...

 
Reply With Quote
 
 
 
 
faisalmooraby.subscription@googlemail.com
Guest
Posts: n/a
 
      30th Oct 2007
Guys

I managed to solve the problem using the same methodology as Greg
Wilson's Color Palette example.
http://groups.google.co.uk/group/mic...25fde7683f983b


Here is how i did it (in 4 Steps):
STEP 1: Copy and paste the following codes in a Module (under
subroutine showform replace the name of the created form
appropriately):
==========================================================
Sub MakeLineStyleSelection()
Dim i, ii, iii
Dim UFrm As Object
Dim Frm, FrmLn
Dim CBox

Set UFrm = ThisWorkbook.VBProject.VBComponents.Add(3)
With UFrm
.Properties("Height") = 180
.Properties("Width") = 110
.Properties("Caption") = "Line Style Selection"

For i = 0 To 26
Set FrmLn = UFrm.designer.Controls.Add("Forms.Frame.1")
With FrmLn
.Left = 10 + i
.Top = 24
.Height = 1
.Width = 1
.BackColor = RGB(0, 0, 0)
.ForeColor = RGB(0, 0, 0)
.SpecialEffect = 0
.Caption = ""
.ControlTipText = "Part" + Str(i)
.BorderStyle = 0
.Enabled = True
End With
Next i

Set Frm = .designer.Controls.Add("Forms.Frame.1")
With Frm
.Caption = "Line Styles"
.ForeColor = RGB(20, 20, 100)
.Enabled = True
.Top = 35
.Left = 10
.Width = 87
.Height = 115
End With
End With


For i = 0 To 26
Set Ctrl = Frm.Controls.Add("Forms.Frame.1")
With Ctrl
.Left = 10 + i
.Top = 20
.Height = 1
.Width = 1
.BackColor = RGB(0, 0, 0)
.ForeColor = RGB(0, 0, 0)
.SpecialEffect = 0
.Caption = ""
.ControlTipText = i
.BorderStyle = 0
.Enabled = True
End With
Next i
Set Ctrl = Frm.Controls.Add("Forms.OptionButton.1")
With Ctrl
.Left = 40
.Top = 12
.Caption = "1"
.BackStyle = 0
.Value = True
End With



For i = 0 To 26
Set Ctrl = Frm.Controls.Add("Forms.Frame.1")
If i Mod 2 = 0 Then
With Ctrl
.Left = 10 + i
.Top = 30
.Height = 1
.Width = 1
.BackColor = RGB(0, 0, 0)
.ForeColor = RGB(0, 0, 0)
.BorderColor = RGB(0, 0, 0)
.SpecialEffect = 0
.Caption = ""
.ControlTipText = i + 27
.BorderStyle = 0
.Enabled = True
End With
Else
With Ctrl
.Left = 10 + i
.Top = 30
.Height = 1
.Width = 1
.BackColor = UFrm.designer.BackColor
.ForeColor = UFrm.designer.BackColor
.BorderColor = UFrm.designer.BackColor
.SpecialEffect = 0
.Caption = ""
.ControlTipText = i + 27
.BorderStyle = 0
.Enabled = True
End With
End If
Next i
Set Ctrl = Frm.Controls.Add("Forms.OptionButton.1")
With Ctrl
.Left = 40
.Top = 22
.Caption = "2"
.BackStyle = 0
End With

For i = 0 To 26
Set Ctrl = Frm.Controls.Add("Forms.Frame.1")
If (i - 2) Mod 4 = 0 Or (i - 3) Mod 4 = 0 Then
With Ctrl
.Left = 10 + i
.Top = 40
.Height = 1
.Width = 1
.BackColor = UFrm.designer.BackColor
.ForeColor = UFrm.designer.BackColor
.BorderColor = UFrm.designer.BackColor
.SpecialEffect = 0
.Caption = ""
.ControlTipText = i + 53
.BorderStyle = 0
.Enabled = True
End With
Else
With Ctrl
.Left = 10 + i
.Top = 40
.Height = 1
.Width = 1
.BackColor = RGB(0, 0, 0)
.ForeColor = RGB(0, 0, 0)
.BorderColor = RGB(0, 0, 0)
.SpecialEffect = 0
.Caption = ""
.ControlTipText = i + 53
.BorderStyle = 0
.Enabled = True
End With
End If
Next i
Set Ctrl = Frm.Controls.Add("Forms.OptionButton.1")
With Ctrl
.Left = 40
.Top = 32
.Caption = "3"
.BackStyle = 0
End With

For i = 0 To 26
Mod_Val = i Mod 10
Set Ctrl = Frm.Controls.Add("Forms.Frame.1")
If Mod_Val = 0 Or Mod_Val = 1 Or Mod_Val = 4 Or Mod_Val = 5 Or
Mod_Val = 6 Or Mod_Val = 7 Then
With Ctrl
.Left = 10 + i
.Top = 50
.Height = 1
.Width = 1
.BackColor = RGB(0, 0, 0)
.ForeColor = RGB(0, 0, 0)
.BorderColor = RGB(0, 0, 0)
.SpecialEffect = 0
.Caption = ""
.ControlTipText = i + 79
.BorderStyle = 0
.Enabled = True
End With
Else
With Ctrl
.Left = 10 + i
.Top = 50
.Height = 1
.Width = 1
.BackColor = UFrm.designer.BackColor
.ForeColor = UFrm.designer.BackColor
.BorderColor = UFrm.designer.BackColor
.SpecialEffect = 0
.Caption = ""
.ControlTipText = i + 79
.BorderStyle = 0
.Enabled = True
End With
End If
Next i
Set Ctrl = Frm.Controls.Add("Forms.OptionButton.1")
With Ctrl
.Left = 40
.Top = 42
.Caption = "4"
.BackStyle = 0
End With

For i = 0 To 26
Set Ctrl = Frm.Controls.Add("Forms.Frame.1")
If i = 2 Or i = 3 Or i = 10 Or i = 11 Or i = 14 Or i = 15 Or i
= 22 Or i = 23 Then
With Ctrl
.Left = 10 + i
.Top = 60
.Height = 1
.Width = 1
.BackColor = UFrm.designer.BackColor
.ForeColor = UFrm.designer.BackColor
.BorderColor = UFrm.designer.BackColor
.SpecialEffect = 0
.Caption = ""
.ControlTipText = i + 105
.BorderStyle = 0
.Enabled = True
End With
Else
With Ctrl
.Left = 10 + i
.Top = 60
.Height = 1
.Width = 1
.BackColor = RGB(0, 0, 0)
.ForeColor = RGB(0, 0, 0)
.BorderColor = RGB(0, 0, 0)
.SpecialEffect = 0
.Caption = ""
.ControlTipText = i + 105
.BorderStyle = 0
.Enabled = True

End With
End If
Next i
Set Ctrl = Frm.Controls.Add("Forms.OptionButton.1")
With Ctrl
.Left = 40
.Top = 52
.Caption = "5"
.BackStyle = 0
End With
End Sub

Sub showform()
UserForm3.Show

End Sub

======================================

STEP 2: Run the MakeLineStyleSelection Subroutine

STEP 3: Paste the following Code under the Code Pane for the created
form (this case assumes that the form is UserForm3, so replace
appropriately):
======================================
Private Sub OptionButton1_Click()
Dim MyContrl As Control
For i = 0 To 26
For Each MyContrl In Controls
If MyContrl.ControlTipText = "Part" + Str(i) Then
Set Ctrl = MyContrl
End If
Next
With Ctrl
.BackColor = RGB(0, 0, 0)
.ForeColor = RGB(0, 0, 0)
.SpecialEffect = 0
.Caption = ""
.BorderStyle = 0
.Enabled = True
End With
Next i

End Sub

Private Sub OptionButton2_Click()
Dim MyContrl As Control
For i = 0 To 26
ii = i + 1

For Each MyContrl In Controls
If MyContrl.ControlTipText = "Part" + Str(i) Then
Set Ctrl = MyContrl
End If
Next
If i Mod 2 = 0 Then
With Ctrl
.BackColor = RGB(0, 0, 0)
.ForeColor = RGB(0, 0, 0)
.BorderColor = RGB(0, 0, 0)
.SpecialEffect = 0
.Caption = ""
.BorderStyle = 0
.Enabled = True
End With
Else
With Ctrl
.BackColor = UserForm3.BackColor
.ForeColor = UserForm3.BackColor
.BorderColor = UserForm3.BackColor
.SpecialEffect = 0
.Caption = ""
.BorderStyle = 0
.Enabled = True
End With
End If
Next i

End Sub
Private Sub OptionButton3_Click()
Dim MyContrl As Control

For i = 0 To 26
ii = i + 1

For Each MyContrl In Controls
If MyContrl.ControlTipText = "Part" + Str(i) Then
Set Ctrl = MyContrl
End If
Next
If (i - 2) Mod 4 = 0 Or (i - 3) Mod 4 = 0 Then
With Ctrl
.BackColor = UserForm3.BackColor
.ForeColor = UserForm3.BackColor
.BorderColor = UserForm3.BackColor
.SpecialEffect = 0
.BorderStyle = 0
.Enabled = True
End With
Else
With Ctrl
.BackColor = RGB(0, 0, 0)
.ForeColor = RGB(0, 0, 0)
.BorderColor = RGB(0, 0, 0)
.SpecialEffect = 0
.BorderStyle = 0
.Enabled = True
End With
End If
Next i
End Sub
Private Sub OptionButton4_Click()
Dim MyContrl As Control

For i = 0 To 26
ii = i + 1
For Each MyContrl In Controls
If MyContrl.ControlTipText = "Part" + Str(i) Then
Set Ctrl = MyContrl
End If
Next
Mod_Val = i Mod 10
If Mod_Val = 0 Or Mod_Val = 1 Or Mod_Val = 4 Or Mod_Val = 5 Or
Mod_Val = 6 Or Mod_Val = 7 Then
With Ctrl
.BackColor = RGB(0, 0, 0)
.ForeColor = RGB(0, 0, 0)
.BorderColor = RGB(0, 0, 0)
.SpecialEffect = 0
.BorderStyle = 0
.Enabled = True
End With
Else
With Ctrl
.BackColor = UserForm3.BackColor
.ForeColor = UserForm3.BackColor
.BorderColor = UserForm3.BackColor
.SpecialEffect = 0
.BorderStyle = 0
.Enabled = True
End With
End If
Next i
End Sub
Private Sub OptionButton5_Click()
Dim MyContrl As Control
For i = 0 To 26
ii = i + 1
For Each MyContrl In Controls
If MyContrl.ControlTipText = "Part" + Str(i) Then
Set Ctrl = MyContrl
End If
Next

If i = 2 Or i = 3 Or i = 10 Or i = 11 Or i = 14 Or i = 15 Or i
= 22 Or i = 23 Then
With Ctrl
.BackColor = UserForm3.BackColor
.ForeColor = UserForm3.BackColor
.BorderColor = UserForm3.BackColor
.SpecialEffect = 0
.BorderStyle = 0
.Enabled = True
End With
Else
With Ctrl
.BackColor = RGB(0, 0, 0)
.ForeColor = RGB(0, 0, 0)
.BorderColor = RGB(0, 0, 0)
.SpecialEffect = 0
.BorderStyle = 0
.Enabled = True

End With
End If
Next i
End Sub
=================================

STEP 4: Run subroutine ShowForm


Thanks Greg.

Faisal...

On Oct 26, 6:20 pm, faisalmooraby.subscript...@googlemail.com wrote:
> Hello Listers
>
> I am looking for a way of adding Line style on a form. Basically, the
> user will choose the line width (from combo) and the line width (on
> the form) changes accordingly.
>
> This will be used with another programs api (which I have done in the
> past) - Mapinfo.
>
> I look forward for your response. If you need more info, please let
> me know.
>
> Faisal...



 
Reply With Quote
 
faisalmooraby.subscription@googlemail.com
Guest
Posts: n/a
 
      30th Oct 2007
The current code does not include line width but this should not be
difficult (anymore)

Faisal...
On Oct 30, 4:34 pm, faisalmooraby.subscript...@googlemail.com wrote:
> Guys
>
> I managed to solve the problem using the same methodology as Greg
> Wilson's Color Palette example.http://groups.google.co.uk/group/mic....programming/b...
>
> Here is how i did it (in 4 Steps):
> STEP 1: Copy and paste the following codes in a Module (under
> subroutine showform replace the name of the created form
> appropriately):
> ==========================================================
> Sub MakeLineStyleSelection()
> Dim i, ii, iii
> Dim UFrm As Object
> Dim Frm, FrmLn
> Dim CBox
>
> Set UFrm = ThisWorkbook.VBProject.VBComponents.Add(3)
> With UFrm
> .Properties("Height") = 180
> .Properties("Width") = 110
> .Properties("Caption") = "Line Style Selection"
>
> For i = 0 To 26
> Set FrmLn = UFrm.designer.Controls.Add("Forms.Frame.1")
> With FrmLn
> .Left = 10 + i
> .Top = 24
> .Height = 1
> .Width = 1
> .BackColor = RGB(0, 0, 0)
> .ForeColor = RGB(0, 0, 0)
> .SpecialEffect = 0
> .Caption = ""
> .ControlTipText = "Part" + Str(i)
> .BorderStyle = 0
> .Enabled = True
> End With
> Next i
>
> Set Frm = .designer.Controls.Add("Forms.Frame.1")
> With Frm
> .Caption = "Line Styles"
> .ForeColor = RGB(20, 20, 100)
> .Enabled = True
> .Top = 35
> .Left = 10
> .Width = 87
> .Height = 115
> End With
> End With
>
> For i = 0 To 26
> Set Ctrl = Frm.Controls.Add("Forms.Frame.1")
> With Ctrl
> .Left = 10 + i
> .Top = 20
> .Height = 1
> .Width = 1
> .BackColor = RGB(0, 0, 0)
> .ForeColor = RGB(0, 0, 0)
> .SpecialEffect = 0
> .Caption = ""
> .ControlTipText = i
> .BorderStyle = 0
> .Enabled = True
> End With
> Next i
> Set Ctrl = Frm.Controls.Add("Forms.OptionButton.1")
> With Ctrl
> .Left = 40
> .Top = 12
> .Caption = "1"
> .BackStyle = 0
> .Value = True
> End With
>
> For i = 0 To 26
> Set Ctrl = Frm.Controls.Add("Forms.Frame.1")
> If i Mod 2 = 0 Then
> With Ctrl
> .Left = 10 + i
> .Top = 30
> .Height = 1
> .Width = 1
> .BackColor = RGB(0, 0, 0)
> .ForeColor = RGB(0, 0, 0)
> .BorderColor = RGB(0, 0, 0)
> .SpecialEffect = 0
> .Caption = ""
> .ControlTipText = i + 27
> .BorderStyle = 0
> .Enabled = True
> End With
> Else
> With Ctrl
> .Left = 10 + i
> .Top = 30
> .Height = 1
> .Width = 1
> .BackColor = UFrm.designer.BackColor
> .ForeColor = UFrm.designer.BackColor
> .BorderColor = UFrm.designer.BackColor
> .SpecialEffect = 0
> .Caption = ""
> .ControlTipText = i + 27
> .BorderStyle = 0
> .Enabled = True
> End With
> End If
> Next i
> Set Ctrl = Frm.Controls.Add("Forms.OptionButton.1")
> With Ctrl
> .Left = 40
> .Top = 22
> .Caption = "2"
> .BackStyle = 0
> End With
>
> For i = 0 To 26
> Set Ctrl = Frm.Controls.Add("Forms.Frame.1")
> If (i - 2) Mod 4 = 0 Or (i - 3) Mod 4 = 0 Then
> With Ctrl
> .Left = 10 + i
> .Top = 40
> .Height = 1
> .Width = 1
> .BackColor = UFrm.designer.BackColor
> .ForeColor = UFrm.designer.BackColor
> .BorderColor = UFrm.designer.BackColor
> .SpecialEffect = 0
> .Caption = ""
> .ControlTipText = i + 53
> .BorderStyle = 0
> .Enabled = True
> End With
> Else
> With Ctrl
> .Left = 10 + i
> .Top = 40
> .Height = 1
> .Width = 1
> .BackColor = RGB(0, 0, 0)
> .ForeColor = RGB(0, 0, 0)
> .BorderColor = RGB(0, 0, 0)
> .SpecialEffect = 0
> .Caption = ""
> .ControlTipText = i + 53
> .BorderStyle = 0
> .Enabled = True
> End With
> End If
> Next i
> Set Ctrl = Frm.Controls.Add("Forms.OptionButton.1")
> With Ctrl
> .Left = 40
> .Top = 32
> .Caption = "3"
> .BackStyle = 0
> End With
>
> For i = 0 To 26
> Mod_Val = i Mod 10
> Set Ctrl = Frm.Controls.Add("Forms.Frame.1")
> If Mod_Val = 0 Or Mod_Val = 1 Or Mod_Val = 4 Or Mod_Val =5 Or
> Mod_Val = 6 Or Mod_Val = 7 Then
> With Ctrl
> .Left = 10 + i
> .Top = 50
> .Height = 1
> .Width = 1
> .BackColor = RGB(0, 0, 0)
> .ForeColor = RGB(0, 0, 0)
> .BorderColor = RGB(0, 0, 0)
> .SpecialEffect = 0
> .Caption = ""
> .ControlTipText = i + 79
> .BorderStyle = 0
> .Enabled = True
> End With
> Else
> With Ctrl
> .Left = 10 + i
> .Top = 50
> .Height = 1
> .Width = 1
> .BackColor = UFrm.designer.BackColor
> .ForeColor = UFrm.designer.BackColor
> .BorderColor = UFrm.designer.BackColor
> .SpecialEffect = 0
> .Caption = ""
> .ControlTipText = i + 79
> .BorderStyle = 0
> .Enabled = True
> End With
> End If
> Next i
> Set Ctrl = Frm.Controls.Add("Forms.OptionButton.1")
> With Ctrl
> .Left = 40
> .Top = 42
> .Caption = "4"
> .BackStyle = 0
> End With
>
> For i = 0 To 26
> Set Ctrl = Frm.Controls.Add("Forms.Frame.1")
> If i = 2 Or i = 3 Or i = 10 Or i = 11 Or i = 14 Or i = 15 Or i
> = 22 Or i = 23 Then
> With Ctrl
> .Left = 10 + i
> .Top = 60
> .Height = 1
> .Width = 1
> .BackColor = UFrm.designer.BackColor
> .ForeColor = UFrm.designer.BackColor
> .BorderColor = UFrm.designer.BackColor
> .SpecialEffect = 0
> .Caption = ""
> .ControlTipText = i + 105
> .BorderStyle = 0
> .Enabled = True
> End With
> Else
> With Ctrl
> .Left = 10 + i
> .Top = 60
> .Height = 1
> .Width = 1
> .BackColor = RGB(0, 0, 0)
> .ForeColor = RGB(0, 0, 0)
> .BorderColor = RGB(0, 0, 0)
> .SpecialEffect = 0
> .Caption = ""
> .ControlTipText = i + 105
> .BorderStyle = 0
> .Enabled = True
>
> End With
> End If
> Next i
> Set Ctrl = Frm.Controls.Add("Forms.OptionButton.1")
> With Ctrl
> .Left = 40
> .Top = 52
> .Caption = "5"
> .BackStyle = 0
> End With
> End Sub
>
> Sub showform()
> UserForm3.Show
>
> End Sub
>
> ======================================
>
> STEP 2: Run the MakeLineStyleSelection Subroutine
>
> STEP 3: Paste the following Code under the Code Pane for the created
> form (this case assumes that the form is UserForm3, so replace
> appropriately):
> ======================================
> Private Sub OptionButton1_Click()
> Dim MyContrl As Control
> For i = 0 To 26
> For Each MyContrl In Controls
> If MyContrl.ControlTipText = "Part" + Str(i) Then
> Set Ctrl = MyContrl
> End If
> Next
> With Ctrl
> .BackColor = RGB(0, 0, 0)
> .ForeColor = RGB(0, 0, 0)
> .SpecialEffect = 0
> .Caption = ""
> .BorderStyle = 0
> .Enabled = True
> End With
> Next i
>
> End Sub
>
> Private Sub OptionButton2_Click()
> Dim MyContrl As Control
> For i = 0 To 26
> ii = i + 1
>
> For Each MyContrl In Controls
> If MyContrl.ControlTipText = "Part" + Str(i) Then
> Set Ctrl = MyContrl
> End If
> Next
> If i Mod 2 = 0 Then
> With Ctrl
> .BackColor = RGB(0, 0, 0)
> .ForeColor = RGB(0, 0, 0)
> .BorderColor = RGB(0, 0, 0)
> .SpecialEffect = 0
> .Caption = ""
> .BorderStyle = 0
> .Enabled = True
> End With
> Else
> With Ctrl
> .BackColor = UserForm3.BackColor
> .ForeColor = UserForm3.BackColor
> .BorderColor = UserForm3.BackColor
> .SpecialEffect = 0
> .Caption = ""
> .BorderStyle = 0
> .Enabled = True
> End With
> End If
> Next i
>
> End Sub
> Private Sub OptionButton3_Click()
> Dim MyContrl As Control
>
> For i = 0 To 26
> ii = i + 1
>
> For Each MyContrl In Controls
> If MyContrl.ControlTipText = "Part" + Str(i) Then
> Set Ctrl = MyContrl
> End If
> Next
> If (i - 2) Mod 4 = 0 Or (i - 3) Mod 4 = 0 Then
> With Ctrl
> .BackColor = UserForm3.BackColor
> .ForeColor = UserForm3.BackColor
> .BorderColor = UserForm3.BackColor
> .SpecialEffect = 0
> .BorderStyle = 0
> .Enabled = True
> End With
> Else
> With Ctrl
> .BackColor = RGB(0, 0, 0)
> .ForeColor = RGB(0, 0, 0)
> .BorderColor = RGB(0, 0, 0)
> .SpecialEffect = 0
> .BorderStyle = 0
> .Enabled = True
> End With
> End If
> Next i
> End Sub
> Private Sub OptionButton4_Click()
> Dim MyContrl As Control
>
> For i = 0 To 26
> ii = i + 1
> For Each MyContrl In Controls
> If MyContrl.ControlTipText = "Part" + Str(i) Then
> Set Ctrl = MyContrl
> End If
> Next
> Mod_Val = i Mod 10
> If Mod_Val = 0 Or Mod_Val = 1 Or Mod_Val = 4 Or Mod_Val =5 Or
> Mod_Val = 6 Or Mod_Val = 7 Then
> With Ctrl
> .BackColor = RGB(0, 0, 0)
> .ForeColor = RGB(0, 0, 0)
> .BorderColor = RGB(0, 0, 0)
> .SpecialEffect = 0
> .BorderStyle = 0
> ...
>
> read more »



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
For "Marker Line Style" see Point.Format.Line.Weight SysMod Microsoft Excel Charting 2 13th May 2009 08:38 AM
Problem adding vertical marker line to line chart lbb Microsoft Excel Charting 6 9th Jan 2009 09:02 AM
Line numbering started adding an {1} to the left of the line numbe =?Utf-8?B?bWljaA==?= Microsoft Word Document Management 1 4th Aug 2005 03:47 PM
line style, dash style, arror style not working BJ Microsoft Word New Users 2 12th Sep 2003 09:35 PM
Changing line style makes line drawing very slow Bart Microsoft C# .NET 1 11th Jul 2003 05:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:42 AM.