Form with Input Dialog Box Have Textbox and Button Error

Lin100

Well-known member
Joined
Dec 12, 2022
Messages
69
Programming Experience
10+
Error CS0104 'TextBox' is an ambiguous reference between 'System.Windows.Forms.TextBox'
and 'System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox' Line 50

Error CS0104 'Button' is an ambiguous reference between 'System.Windows.Forms.Button'
and 'System.Windows.Forms.VisualStyles.VisualStyleElement.Button' Line 51

Error CS0104 'Button' is an ambiguous reference between 'System.Windows.Forms.Button'
and 'System.Windows.Forms.VisualStyles.VisualStyleElement.Button' Line 52

/////////////////////////////////////////////////////////////

Reservation2 With Input Dialog Box:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace Apartment_Management
{
    public partial class Reservation2 : Form
    {
        public Reservation2()
        {
            InitializeComponent();
        }

        private void Reservation2_Load(object sender, EventArgs e)
        {
            this.reservationTableAdapter1.Fill(this.aMS_2007DataSet.Reservation);
        }

        private void Move_In_Click(object sender, EventArgs e)
        {
            string value = "";
            if (InputBox("Dialog Box", "Please enter the date that the tenant will move in.", ref value) == DialogResult.OK)
            {
                labelResponseInput.Visible = true;
                labelResponseInput.Text = "Your name: " + value;
            }

            DialogResult InputBox(string title, string promptText, ref string Input_Value)
            {
                Form form = new Form();
                Label label = new Label();
                TextBox textBox = new TextBox();           //ERROR CS104
                Button buttonOk = new Button();          //ERROR CS104
                Button buttonCancel = new Button();    //ERROR CS104

                form.Text = title;
                label.Text = promptText;

                buttonOk.Text = "OK";
                buttonCancel.Text = "Cancel";
                buttonOk.DialogResult = DialogResult.OK;
                buttonCancel.DialogResult = DialogResult.Cancel;

                label.SetBounds(36, 36, 372, 13);
                textBox.SetBounds(36, 86, 700, 20);
                buttonOk.SetBounds(228, 160, 160, 60);
                buttonCancel.SetBounds(400, 160, 160, 60);

                label.AutoSize = true;
                form.ClientSize = new Size(796, 307);
                form.FormBorderStyle = FormBorderStyle.FixedDialog;
                form.StartPosition = FormStartPosition.CenterScreen;
                form.MinimizeBox = false;
                form.MaximizeBox = false;

                form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
                form.AcceptButton = buttonOk;
                form.CancelButton = buttonCancel;

                DialogResult dialogResult = form.ShowDialog();
                value = textBox.Text;
                return dialogResult;
            }

        }
    }
}
 
The error is accurate. Both namespaces identified have a TextBox and Button classes in them. So the compiler doesn't know if you want to use the WinForms version or the WPF version of those classes.

It looks like you chose the wrong project type when you started out. You need to pick WinForms (aka Windows Forms), not WPF (aka Windows Presentation Framework) when creating your project.
 
No, it's all Windows Forms, System.Windows.Forms.VisualStyles is for custom rendering, comment out line 10, or change it to using System.Windows.Forms.VisualStyles namespace. (VisualStyleElement is a class).
 
No, it's all Windows Forms, System.Windows.Forms.VisualStyles is for custom rendering, comment out line 10, or change it to using System.Windows.Forms.VisualStyles namespace. (VisualStyleElement is a class).
Thank you JohnH and Skydiver for your assistant. I commented out line 10 and now it is running. You said "System.Windows.Forms.VisualStyles is
for custom rendering." So is custom rendering means for high-end desk-top publishing like graphic design ? If not then what is custom rendering and under what condition would I used System.Windows.Forms.VisualStyles instead of System.Windows.Forms ?
 

Latest posts

Back
Top Bottom