What is the C# version of VB.NET’s InputBox?

Add a reference to Microsoft.VisualBasic, InputBox is in the Microsoft.VisualBasic.Interaction namespace: using Microsoft.VisualBasic; string input = Interaction.InputBox(“Prompt”, “Title”, “Default”, x_coordinate, y_coordinate); Only the first argument for prompt is mandatory

How to find the main() entry point in a VB.Net winforms app?

In VB you’ll need to create your sub main by hand as it were so what I generally do is create a new Module named Program. Within that as a very basic setup you’ll need to add the following code. Public Sub Main() Application.EnableVisualStyles() Application.SetCompatibleTextRenderingDefault(False) Application.Run(New Form1) End Sub Once you’ve done that go to … Read more

VB.net Need Text Box to Only Accept Numbers

You can do this with the use of Ascii integers. Put this code in the Textbox’s Keypress event. e.KeyChar represents the key that’s pressed. And the the built-in function Asc() converts it into its Ascii integer. Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress ’97 – 122 = Ascii codes for … Read more

Consume a SOAP web service without relying on the app.config

The settings in <system.ServiceModel> in the app.config file will tell the component how to connect to the external web service. The xml is simply a textual representation of the necessary classes and enumerations required to make the default connection to the web service. For example, this is the code that was generated for the web … Read more

How to configure SMTP settings in web.config

By setting the values <mailSettings> section of the in the web.config you can just new up an SmtpClient and the client will use those settings. https://learn.microsoft.com/en-us/dotnet/api/system.net.mail.smtpclient.-ctor?view=net-6.0#system-net-mail-smtpclient-ctor Web.Config file: <configuration> <system.net> <mailSettings> <smtp from=”yourmail@gmail.com”> <network host=”smtp.gmail.com” port=”587″ userName=”yourmail@gmail.com” password=”yourpassword” enableSsl=”true”/> </smtp> </mailSettings> </system.net> </configuration> C#: SmtpClient smtpClient = new SmtpClient(); smtpClient.Send(msgMail); However, if authentication is needed, … Read more

Redirect Trace output to Console

You can add the following to your exe’s .config file. <?xml version=”1.0″?> <configuration> <system.diagnostics> <trace autoflush=”true”> <listeners> <add name=”logListener” type=”System.Diagnostics.TextWriterTraceListener” initializeData=”cat.log” /> <add name=”consoleListener” type=”System.Diagnostics.ConsoleTraceListener”/> </listeners> </trace> </system.diagnostics> </configuration> I included the TextWriter as well, in case you’re interested in logging to a file.