hong kai hong kai - 27 days ago 9
C# Question

argument 1 string to System.Windows.Forms.iwin32window

I'm Newbie in Visual Studio.
I was getting an error about this code.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MetroFramework;

namespace NewUIStyle
{
public partial class Form1 : MetroFramework.Forms.MetroForm
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void metroLink1_Click(object sender, EventArgs e)
{
if (metroTextBox1.Text=="admin" || metroTextBox2.Text=="123")
{
Form2 settingsForm = new Form2();

settingsForm.Show();
} else
{
MetroMessageBox.Show("Invaild Username or Password", "Error!");
}
}
}
}


The error message coming from the MetroMessageBox.Show("Invaild Username or Password", "Error");

Answer

You're missing the owner of window in first parameter of Show() call. Try pass this (or null, if you don't want to provide an owner Window):

MetroMessageBox.Show(this, "Invaild Username or Password", "Error!");
Comments