devilonline
September 24th, 2009, 09:18 AM
hi, i'm learning c# by this book: "Wrox beginning c sharp 3.0 an introdution...." however the code he puts there never works fine for me. for exemple i have this code: "has more than one entry point defined: "windowsFormsApllication3.Main(). compile with /main to specficy the type that contains the entry point" how can i solve this. sorry im at the begining. (how can i put the code here?)
here is the 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 WindowsFormsApplication3
{
public partial class frmain : Form
{
private Label label1;
private TextBox txtLongDate;
private Label label2;
private TextBox txtShortDate;
private Label label3;
private TextBox txtGeneralDateAndTime;
private Label label4;
private TextBox txtLongTime;
private Label label5;
private TextBox txtShortTime;
private Label label6;
private TextBox txtDaysToNewYears;
private Label label7;
private Button btnClose;
private Button btnRefresh;
private TextBox txtCompleteDateAndTime;
#region Windows code
#endregion
public frmain()
{
InitializeComponent();
UpdateTimeInfo(); // Update textboxes
}
public static void Main()
{
frmMain main = new frmMain();
Application.Run(main);
}
private void UpdateTimeInfo()
{
int days;
DateTime myTime = new DateTime();
myTime = DateTime.Now;
DateTime newYears = new DateTime(myTime.Year, 12, 31);
txtCompleteDateAndTime.Text = myTime.ToString("f");
txtLongDate.Text = myTime.ToString("D");
txtShortDate.Text = myTime.ToString("d");
txtGeneralDateAndTime.Text = myTime.ToString("g");
txtLongTime.Text = myTime.ToString("T");
txtShortTime.Text = myTime.ToString("t");
days = newYears.DayOfYear - myTime.DayOfYear;
txtDaysToNewYears.Text = days.ToString();
}
private void btnRefresh_Click(object sender, EventArgs e)
{
UpdateTimeInfo();
}
private void btnClose_Click(object sender, EventArgs e)
{
Close();
}
}
}
thanks
here is the 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 WindowsFormsApplication3
{
public partial class frmain : Form
{
private Label label1;
private TextBox txtLongDate;
private Label label2;
private TextBox txtShortDate;
private Label label3;
private TextBox txtGeneralDateAndTime;
private Label label4;
private TextBox txtLongTime;
private Label label5;
private TextBox txtShortTime;
private Label label6;
private TextBox txtDaysToNewYears;
private Label label7;
private Button btnClose;
private Button btnRefresh;
private TextBox txtCompleteDateAndTime;
#region Windows code
#endregion
public frmain()
{
InitializeComponent();
UpdateTimeInfo(); // Update textboxes
}
public static void Main()
{
frmMain main = new frmMain();
Application.Run(main);
}
private void UpdateTimeInfo()
{
int days;
DateTime myTime = new DateTime();
myTime = DateTime.Now;
DateTime newYears = new DateTime(myTime.Year, 12, 31);
txtCompleteDateAndTime.Text = myTime.ToString("f");
txtLongDate.Text = myTime.ToString("D");
txtShortDate.Text = myTime.ToString("d");
txtGeneralDateAndTime.Text = myTime.ToString("g");
txtLongTime.Text = myTime.ToString("T");
txtShortTime.Text = myTime.ToString("t");
days = newYears.DayOfYear - myTime.DayOfYear;
txtDaysToNewYears.Text = days.ToString();
}
private void btnRefresh_Click(object sender, EventArgs e)
{
UpdateTimeInfo();
}
private void btnClose_Click(object sender, EventArgs e)
{
Close();
}
}
}
thanks