- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all.
I am working with a vb form instead of a ilogic form. Reasing being that I want to have adaptible number of checkboxes to represent the number of views in a drawing. I have an example that I found online to make the forms, wich all works fine.
The problem I have is that there are some things inside the code I Haven't used before like "public class", "public sub" etc..
I have made a simple function that just returns the number of views on a drawing. The idea is then that the form only shows as much checkboxes as there are views. And also in a later stage the description would match the view.
The problem is that if I call it from one class it works. But if I put it in the other class it does not and returns 'thisdoc' is not declared.
I'm guessing I need to add an import or a reference somewhere, but I don't know what and I don't know where.
The getviews function works, the getviews2 function gives the error.
Any help is much appreciated.
Public Class RunMyForm
Private Sub Main
MsgBox (getviews)
' Create new instance of the custom form
Dim myfrm As New CustomForm
' Use ShowDialog so it waits for user / form close before continuing
'MsgBox(myfrm.ShowDialog())
Dim oResult As CustomForm.CustomDialogResult = myfrm.ShowDialog
' Display the custom form result
' MessageBox.Show(oResult)
End Sub
Function getviews As Integer
Dim odoc As Document
Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisDoc.Document
getviews = 0
For Each oView In oDrawingDoc.ActiveSheet.DrawingViews
getviews = getviews + 1
'MsgBox(oView.ReferencedDocumentDescriptor.ReferencedDocument.displayname)
Next
End Function
End Class
Public Class CustomForm
Inherits System.Windows.Forms.Form
Public myResult As String = "TestResultHere"
Public myProp1 As String = "TestProperty"
Function getviews2 As Integer
Dim odoc As Document
Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisDoc.Document
getviews2 = 0
For Each oView In oDrawingDoc.ActiveSheet.DrawingViews
getviews2 = getviews2 + 1
'MsgBox(oView.ReferencedDocumentDescriptor.ReferencedDocument.displayname)
Next
End Function
Public Sub New()
' This is run when a new instance of the form is created
oForm = Me
With oForm
' Set up form
.FormBorderStyle = FormBorderStyle.FixedToolWindow 'Fixed3D / FixedDialog / FixedSingle / FixedToolWindow / None / Sizable / SizableToolWindow
'.MaximizeBox = False
'.MinimizeBox = False
.StartPosition = FormStartPosition.CenterScreen
.Width = 600
.Height = 500
.TopMost = True
.Text = "Custom Form"
.Name = "Custom Form"
End With
Dim Button1 As New Button()
With Button1
'.Font = myfnt
.Text = "test"
'.Width = 100
'.Height = 100
.Top = 25
.Left = 25
.Enabled = True
End With
Dim i As Integer = 0
Dim offset = 10
Do While i <> 5
i = i + 1
Dim checkbox = New CheckBox()
oForm.Controls.Add(checkbox)
checkbox.Top = 100 + i*20
checkbox.Left = 50
checkbox.Text = "checkbox" & i
checkbox.Checked = True
Loop
'Add your Event handler
AddHandler Button1.Click, AddressOf Button1_Click
oForm.Controls.Add(Button1)
' Assign dialog result for the form (note this returns 0 based index of the enumerator
Me.DialogResult = CustomDialogResult.Slope4
'MessageBox.Show(GetGroupBoxCheckedButton(oGB).Text)
End Sub
Private Sub CustomForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If MessageBox.Show("Are you sure to close this application?", "Close", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.Yes Then
Else
e.Cancel = True
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal E As System.EventArgs)
myResult = "testing clicked button"
'sender.parent.Close ' Accesses the form and closes after button click
' Can also direct cast to object "DirectCast"
Dim ores As CustomDialogResult = CustomDialogResult.Slope2
MessageBox.Show(ores.ToString)
End Sub
' Create a custom enumerator for windows for result
Public Enum CustomDialogResult
Slope1
Slope2
Slope3
Slope4
End Enum
End Class
Solved! Go to Solution.