iLogic to create Message Box with image

iLogic to create Message Box with image

davefosz
Contributor Contributor
2,661 Views
4 Replies
Message 1 of 5

iLogic to create Message Box with image

davefosz
Contributor
Contributor

Good afternoon,

Does any one knows how to create a message box with a picture inside using iLogic?

Thanks,

 

Dave

0 Likes
Accepted solutions (1)
2,662 Views
4 Replies
Replies (4)
Message 2 of 5

JaneFan
Autodesk
Autodesk
Hi Dave,

MessageBox can only support text information in it. If you need picture in the dialog, Form in iLogic is recommendated that you can add pictures or any other controls needed.
Please try to add a form in iLogic and add picture control then.



Jane Fan
Inventor/Fusion QA Engineer
0 Likes
Message 3 of 5

davefosz
Contributor
Contributor

Thank you for the reply Jane,

I only found the option to create a global form and call it from iLogic with the command iLogicForm.ShowGlobal

For this case I prefer to have only the iLogic macro so I would like to have the Dialog Box with Picture created in iLogic.

If there is a way to do that I'll appreciate the advice.

Thanks again,

Dave

0 Likes
Message 4 of 5

Owner2229
Advisor
Advisor
Accepted solution

Here you go, you might need to play a bit with the values, but it's a good start:

Blue - code adding form elements

Red - defines the size of the form

Green - shows a textbox (after the form closes) with the values entered in the comboboxes


AddLabel - adds label text
AddCB - adds combobox
AddTB - adds textbox
AddPB - adds picturebox

 

Let me know if you have any further questions or a need for other elements.

 

Imports System
AddReference "System.Drawing.dll"
Imports System.Windows.Forms

Sub Main()
	CreateForm("MyForm")
	MF.ShowDialog()
	MsgBox("ComboBox one value: " & CB(0).Text & vbNewLine & "ComboBox two value: " & CB(1).Text & _
	vbNewLine & "TextBox one value: " & TB(0).Text)
End Sub

Private MF As Form
Public CB(0) As ComboBox
Public TB(0) As TextBox
Public PB(0) As PictureBox

Private Sub CreateForm(Optional Name As String = vbNullString)
	MF = New Form
	MF.Text = Name
	MF.AutoScaleMode = AutoScaleMode.None
	MF.Size = New Drawing.Size(300, 300) 'Width, Heigth
	MF.MinimumSize = MF.Size
	MF.MaximumSize = MF.Size
	MF.Font = New Drawing.Font(MF.Font.FontFamily, 10)
	MF.MaximizeBox = False
	MF.MinimizeBox = False
	MF.ShowIcon = False
	MF.SizeGripStyle = SizeGripStyle.Hide
	MF.StartPosition = FormStartPosition.CenterScreen
	
	AddLabel(5, 5, "Parameter One")
	AddLabel(5, 40, "Parameter Two")
	AddCB(120, 5, {"Option one", "Option two"}, 150)
	AddCB(120, 40, {"Option three", "Option four"}, 150)
	AddTB(120, 75, "sometext", 150)
	AddPB(20, 120, Drawing.Image.FromFile("C:\Path\01.jpg"))
	
	AddExitButton()
End Sub

Private Sub AddLabel(PosX As Integer, PosY As Integer, Caption As String, Optional Width As Integer = 100)
	Dim LC As Integer = MF.Controls.Count + 1
	Dim L1 As New Label
	L1.Name = "L" & LC
	L1.Location = New Drawing.Point(PosX, PosY)
	L1.Text = Caption
	L1.Width = Width
	MF.Controls.Add(L1)
End Sub

Private Sub AddTB(PosX As Integer, PosY As Integer, Optional Caption As String = vbNullString, Optional Width As Integer = 100)
	Dim LC As Integer = TB.Length - 1
	If Not TB(LC) Is Nothing Then
		LC = LC + 1
		ReDim Preserve TB(LC)
	End If
	TB(LC) = New TextBox
	TB(LC).Location = New Drawing.Point(PosX, PosY)
	TB(LC).Name = "TB" & LC
	TB(LC).Text = Caption
	TB(LC).Width = Width
	MF.Controls.Add(TB(LC))
End Sub

Private Sub AddCB(PosX As Integer, PosY As Integer, Values() As String, Optional Width As Integer = 100)
	Dim LC As Integer = CB.Length - 1
	If Not CB(LC) Is Nothing Then
		LC = LC + 1
		ReDim Preserve CB(LC)
	End If
	CB(LC) = New ComboBox
	CB(LC).Location = New Drawing.Point(PosX, PosY)
	CB(LC).Name = "CB" & LC
	CB(LC).Width = Width
	For Each Value As String In Values
		CB(LC).Items.Add(Value)
	Next
	MF.Controls.Add(CB(LC))
End Sub

Private Sub AddPB(PosX As Integer, PosY As Integer, Pic As Drawing.Image)
	If Pic Is Nothing Then Exit Sub
	Dim LC As Integer = PB.Length - 1
	If Not PB(LC) Is Nothing Then
		LC = LC + 1
		ReDim Preserve PB(LC)
	End If
	PB(LC) = New PictureBox
	PB(LC).Location = New Drawing.Point(PosX, PosY)
	PB(LC).Name = "PB" & LC
	PB(LC).Width = Pic.Width
	PB(LC).Height = Pic.Height
	PB(LC).Image = Pic
	MF.Controls.Add(PB(LC))
End Sub

Private Sub AddButton(PosX As Integer, PosY As Integer, Caption As String)
	Dim LC As Integer = MF.Controls.Count + 1
	Dim BT As New Button
	BT.Name = "BT" & LC
	BT.Location = New Drawing.Point(PosX, PosY)
	BT.Text = Caption
	MF.Controls.Add(BT)
End Sub

Private Sub AddExitButton()
	Dim BT As New Button
	BT.Name = "BT_Exit"
	Dim PosX As Integer = MF.Width - (BT.Width * 1.3)
	Dim PosY As Integer = MF.Height - (BT.Height * 3)
	BT.Location = New Drawing.Point(PosX, PosY)
	BT.Text = "OK"
	MF.Controls.Add(BT)
	AddHandler BT.Click, AddressOf Me.ExitButtonClick
End Sub

Private Sub ExitButtonClick()
	MF.Close()
End Sub

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 5 of 5

davefosz
Contributor
Contributor

Thank you Mike, that code works perfectly.

Regards,

Dave