Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

If Iwant to do visual basic buttons on the online vb compiler how do I do it?

+5 votes
asked Mar 23, 2019 by Priya
If I want to do Visual Studio buttons on online gdb VB compiler what code do I write? Because the visual studio looks different.

1 Answer

0 votes
answered Jul 15, 2025 by Jerry Jeremiah (2,040 points)

Ok, so I have figured it out!

Imports System.Windows.Forms

Module VBModule
    Sub Main()
        Application.Run(New Form1())
    End Sub
    
    Friend Class Form1 Inherits Form
        Private btnClickMe As New Button()
        
        Public Sub New()
            Me.Text = "My Simple Form"
            btnClickMe.Text = "Click Me"
            AddHandler btnClickMe.Click, AddressOf btnClickMe_Click
            Me.Controls.Add(btnClickMe)
            Me.Visible = true
        End Sub
        
        Private Sub btnClickMe_Click(sender As Object, e As EventArgs)
            MessageBox.Show("Button was clicked!")
        End Sub
    End Class
End Module

And then instead of running it by hitting "Run" you need to click the little down arrow on the Rub button and choose "Run with display screen (beta)" and it will actually work.  Hitting "Run" doesn't work because it generates this exception:

Unhandled Exception:
The type initializer for 'System.Windows.Forms.XplatUI' threw an exception. ---> System.ArgumentNullException: Could not open display (X-Server required. Check your DISPLAY environment variable)

And that means it is trying to use an XWindows server to display the window.  But the XWindows thing doesn't work (I tried many times) so you need to use the built-in "Run with display screen (beta)" option.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...