Click here to Skip to main content
15,921,941 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this code, it shows only the month button, please show me the error I did

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Globalization;
using System.Linq;
using System.Windows.Forms;

namespace Uis.Calendar
{
public partial class ucCalander : UserControl
{
string[] weekDays = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
string[] MonthArray = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
string[] DayArray = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "..." };

public ucCalander()
{
InitializeComponent();
}

private void ucCalander_Load(object sender, EventArgs e)
{
CreateMonthButtons();
CreateDayButtons();
DisplayWeekDays();
}
# region Button Create
private void CreateMonthButtons()
{
int lnRowMonth = 10;
int lnColMonth = 10;

for (int i = 0; i < 13; i++)
{
MonthButton btnMonth = new MonthButton();
btnMonth.Location = new Point(lnRowMonth, lnColMonth);
btnMonth.Size = new Size(80, 40);
btnMonth.Name = "btnMonth" + i;
btnMonth.Text = MonthArray[i];
btnMonth.BackColor = Color.Yellow;
btnMonth.Click += new EventHandler(btnMonth_Click);
lnColMonth = lnColMonth + 40;
btnMonth.Tag = i.ToString();
this.Controls.Add(btnMonth);
}
}
private void CreateDayButtons()
{
int lnRowDay = 10;
int lnColDay = 10;

for (int i = 0; i < 13; i++)
{
DayButton btnDay = new DayButton();
btnDay.Location = new Point(lnRowDay, lnColDay);
btnDay.Size = new Size(80, 40);
btnDay.Name = "btnDay" + i;
btnDay.Text = DayArray[i];
btnDay.BackColor = Color.Yellow;
btnDay.Click += new EventHandler(btnDay_Click);
lnRowDay = lnRowDay + 70;
btnDay.Tag = i.ToString();
this.Controls.Add(btnDay);
}
}
private void DisplayWeekDays()
{
int lnRowLabel = 150;
int lnColLabel = 10;

for (int i = 0; i < 8; i++)
{
Label lblWeekDays = new Label();
lblWeekDays.Location = new Point(lnRowLabel, lnColLabel);
lblWeekDays.Text = weekDays[i];
lblWeekDays.ForeColor = Color.Red;
lblWeekDays.Font = new Font("Arial", 12, FontStyle.Bold);
lnRowLabel = lnRowLabel + 100;
lblWeekDays.Tag = (i + 12).ToString();
this.Controls.Add(lblWeekDays);
}
}
# endregion Button Create
# region Click
private void btnMonth_Click(object sender, EventArgs e)
{

}
private void btnDay_Click(object sender, EventArgs e)
{

}
# endregion Click

}
}

thanks in advance
Posted

1 solution

I can see all buttons. Some buttons override other buttons due to position set error.
There is error in for loop for all scenario

C#
private void CreateMonthButtons()
{
int lnRowMonth = 10;
int lnColMonth = 10;
 
for (int i = 0; i < 13; i++) // change it to i<12
{


C#
private void CreateDayButtons()
{
int lnRowDay = 100; //position changed
int lnColDay = 10;
 
for (int i = 0; i < 13; i++) // change it to i<10
{


C#
private void DisplayWeekDays()
{
int lnRowLabel = 100; //position changed
int lnColLabel = 50; //position changed
 
for (int i = 0; i < 8; i++) // change it to i<7
{


I can see all buttons if position and loop changed
 
Share this answer
 
v3
Comments
ahmad zrein 16-Aug-14 1:51am    
the problem when I run it it shows only month button, this due I think mistake in add controls
thanks
ahmad zrein 16-Aug-14 1:58am    
it is ok thanks it works fine

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900