C# startup form unable to be shown - c#

This is my first assignment using C# and I've learned briefly about programming with Python in my pre-u. The C# form that I would like to show the user upon logging in can't be shown and instead, the program displays the Built errors msg, where I click on 'Yes' to continue running the last successful build. However, it will show one of the previous forms (which I have deleted from the program) instead - making it hard for me to test run and check for any other errors in my program.
The form I would like to show is TechnicianHome.
Error
There were built errors. Would you like to continue and run the last successful build?
Any help is much appreciated.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ASSIGNMENT
{
public partial class TechnicianHome : Form
{
public static string name;
public TechnicianHome()
{
InitializeComponent();
}
public TechnicianHome (string n)
{
InitializeComponent();
name = n;
}
private void TechnicianHome_Load(object sender, EventArgs e)
{
lblWelcome.Text = "Welcome" + name;
}
private void button1_Click(object sender, EventArgs e)
{
ServiceRequests vr = new ServiceRequests();
this.Hide();
vr.ShowDialog();
}
private void button1_Click_1(object sender, EventArgs e)
{
UpdateProfile up = new UpdateProfile();
this.Hide();
up.ShowDialog();
}
}
}

Related

C# Calling A Flash Variable From Another Form?

I am in need of a bit of help searched around the internet for about 2 days
to try and figure out how i can call an AxShockwaveFlash Variable from a second form this is for a game trainer something simple just getting into C# so i thought id start with one of these however i love everything i make to have a nice look and as many options as i can add so for my first C# Trainer i added a MenuStrip that opens a second form(VariableMods.cs) it has a few radio buttons a text box 3 toggle switches and 2 buttons one for setting a variable to whatever is typed in the text box while checking which radio button is checked and a button to close the variable menu which is another thing i need a bit of help with
-How do i Close the Second Form but still keep my Toggles On?
-How do i Call A Variable From (Form1.cs) to Form2(VariableMods.cs)
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;
namespace OCULAS
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Show the Variable ModMenu
private void openVariableModsToolStripMenuItem_Click(object sender, EventArgs e)
{
VariableMods VarMenu = new VariableMods(this);
VarMenu.Show();
}
//Show About Program Box
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
InfoBox1 AboutBoxx = new InfoBox1();
AboutBoxx.Show();
}
//Close the Program
private void closeToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
That is my Form1 Code Have Not Put anything into it about the ShockwaveFlash yet
And
here is Form2(VariableMods)
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;
namespace OCULAS
{
public partial class VariableMods : Form
{
Form1 originalForm; //Using "OriginalForm" To Call "Form1"
public VariableMods(Form1 IncomingForm)
{
originalForm = IncomingForm; //originalForm(Form1) is the form to be called
InitializeComponent();
BoxHeadVariables utf = new BoxHeadVariables();
}
private void ambiance_Button_21_Click(object sender, EventArgs e)
{
this.Hide();
}
private void ambiance_Button_11_Click(Form1 incomingForm, object sender, EventArgs e)
{
if (ambiance_RadioButton1.Checked == true)
{
MessageBox.Show("Damage Mod Is Active");
}
if (ambiance_RadioButton2.Checked == true)
{
MessageBox.Show("Speed Mod Is Active");
}
if (ambiance_RadioButton3.Checked == true)
{
MessageBox.Show("Range Mod Is Active");
}
}
}
}

Does not contain a static 'Main' method suitable for an entry point in Windows Forms

I am trying to make some library software (For an assignment), but keep getting this error, Despite it working 20min before.
I did originally make this from a Windows Form Application, but do not know what went wrong :(
I have a feeling that this is a "simple" error to fix. But its answer still alludes me.
Program k:\LibrarySoftware\Library_Software\Library_Software\obj\Debug\Library_Software.exe' does not contain a static 'Main' method suitable for an entry point
Library.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Library_Software
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void lblYear_Click(object sender, EventArgs e)
{
}
private void btnAddBook_Click(object sender, EventArgs e)
{
if (Application.OpenForms["Add_Book"] != null)
{
//you can use closing or hiding method
Application.OpenForms["Add_Book"].Close();
//Application.OPenForms["Add_Book"].Hide();
}
Add_Book B = new Add_Book();
B.Show();
}
private void lblNarrator_Click(object sender, EventArgs e)
{
}
private void cbxBookType_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void btnLoadBooks_Click(object sender, EventArgs e)
{
}
private void btnDeleteBook_Click(object sender, EventArgs e)
{
if (Application.OpenForms["Form2"] != null)
{
//you can use closing or hiding method
Application.OpenForms["Form2"].Close();
//Application.OPenForms["Add_Book"].Hide();
}
Form2 D = new Form2();
D.Show();
}
}
}
Also if there are any other errors please point them out
You are missing a main method in your project. The form does not initialize itself, it must be initialized in a method which acts as an entry point for your application.
Creating a new winforms project in VS2012 yields this class:
static class Program {
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
If you do not have a class file "Program.cs" in your project create one and add the code I just provided. The application should then run as expected.
My guess is you deleted the class by accident or something like that.
You need to put your form file into WindowsFormsApplication project.
In your visual studio:
- Go to File -> New Project
- Search for Windows Forms Application
- Fill the textboxes and click Finish
Now you can hit F5 to start the application and eventually add your library form to solution

How to use a query in C# (not web)?

I have created a database in microsoft office access. In form1.cs i added a DataGridView with the source from the database created. In tableDataSet.xsd/tabelAdapter i created a new query with 3 parameters which i use to insert the data in the database ( Name, Password, Age) . how can i use this query with that 3 parameters from 3 different textbox?
PS: i use only Windows Form Application, no asp.net or etc.
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;
namespace lucian
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'jucatoriDataSet.jucator' table. You can move, or remove it, as needed.
this.jucatorTableAdapter.Fill(this.jucatoriDataSet.jucator);
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void adaugareToolStripButton_Click(object sender, EventArgs e)
{
try
{
this.jucatorTableAdapter.Fill(this.jucatoriDataSet.jucator);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
Take a look at that article http://msdn.microsoft.com/en-us/magazine/cc163709.aspx
Basically you need to learn about ADO.NET :)

Multiple form not showing up

I'm trying to make a multiWindowsForm.
Just to try how it is working I started with a a simple form that I added a button to. When clicking on it, another window should pop up. But I can't get it to work. It crashes with error:
Object reference not set to an instance of an object!
I used Project → Add → Windows form and named it Mupp.cs
Here's my code for Form1.cs :
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;
namespace MultiForm
{
public partial class tryout : Form
{
public tryout()
{
InitializeComponent();
}
Mupp theMupp;
private void Form1_Load(object sender, EventArgs e)
{
theMupp = new Mupp();
}
private void button1_Click(object sender, EventArgs e)
{
theMupp.Show();
}
}
}
What can I have missed out on?
It looks like the load event is not firing and thus not initilising your object. Make sure that the load event is hooked up.
Alternatively, initialise in the click event.
private void button1_Click(object sender, EventArgs e)
{
using (Mupp theMupp = new Mupp())
{
theMupp.ShowDialog();
}
}
I hope this helps.
public tryout()
{
InitializeComponent();
this.Load += new EventHandler(Form1_Load);
}

Windows Forms variables generated automatically

I'm following the example from "Programming C# 4.0, 6th edition" for working with Windows Forms, but I get to a point where I can't understand what actually happens. I have 3 files
One with Main() :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace ToDoList
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
one to work with the fields of the form:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class ToDoEntry
{
public string Title { get; set; }
public string Description { get; set; }
public DateTime DueDate { get; set; }
}
And the form itself :
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;
namespace ToDoList
{
public partial class Form1 : Form
{
private BindingList<ToDoEntry> entries = new BindingList<ToDoEntry>();
public Form1()
{
InitializeComponent();
entriesSource.DataSource = entries;
CreateNewItem();
}
private void bindingSource1_CurrentChanged(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void CreateNewItem()
{
ToDoEntry newEntry = (ToDoEntry)entriesSource.AddNew();
newEntry.Title = "New entry";
newEntry.DueDate = DateTime.Now;
entriesSource.ResetCurrentItem();
}
private void entriesSource_ListChanged(object sender, ListChangedEventArgs e)
{
switch (e.ListChangedType)
{
case ListChangedType.ItemAdded:
MakeListViewItemForNewEntry(e.NewIndex);
break;
case ListChangedType.ItemDeleted:
RemoveListViewItem(e.NewIndex);
break;
case ListChangedType.ItemChanged:
UpdateListViewItem(e.NewIndex);
break;
}
}
private void MakeListViewItemForNewEntry(int newItemIndex)
{
ListViewItem item = new ListViewItem();
item.SubItems.Add("");
entriesListView.Items.Insert(newItemIndex, item);
}
private void UpdateListViewItem(int itemIndex)
{
ListViewItem item = entriesListView.Items[itemIndex];
ToDoEntry entry = entries[itemIndex];
item.SubItems[0].Text = entry.Title;
item.SubItems[1].Text = entry.DueDate.ToShortDateString();
}
private void RemoveListViewItem(int deletedItemIndex)
{
entriesListView.Items.RemoveAt(deletedItemIndex);
}
}
}
My problem is with saying that The name entriesListView does not exist in the current context. Which is true, but for example entriesSource.DataSource = entries;
I don't have entriesSource either but for some reason I can use it. Now I'm not sure if the missing class(at least I think it should be a class) is something that VS2010 (Yes I'm using Visual Studio 2010) should generate but then - why it hasn't.
Is something that I should write manually but then, there's nothing about this in the example and I too have no idea how to define entriesListView.
These variables are being created by Visual Studio in a designer file. This is done through the use of the partial keyword, which is a feature in C# that allows you to split a class definition into two or more files.
The designer file will be called Form1.designer.cs in this instance. You can see which controls have been created by opening this file, or, if using Visual Studio, by opening the form in the Visual Studio Designer. To open the designer file in Visual Studio, expand the Form1.cs entry in the Solution Explorer TreeView, and double-click the designer file.
In your code above, the problem appears to be that the entriesListView variable does not exist. It is possible that it was created at one point, and then deleted (this can even happen inadvertently due to Visual Studio bugs). Adding a new ListView to your form and setting the Name property to entriesListView should correct the problem.

Categories

Resources