this.intStepValue = 0;
try
{
for(int i = 0; i < 20; i++)
{
ScheduleLabel slTmp = new ScheduleLabel(0, this.intStepValue,
this.panViewScheduleMain.Width, 20,
Convert.ToInt32(i),
"housenumber" + i.ToString() + " " +
"housenumbersub" + i.ToString() + " " +
"streetaddress" + i.ToString() + " " +
"postcode" + i.ToString() + " ",
"job_response_details" + i.ToString(), JobPriority.High, this.lblJobDetails);
this.panViewScheduleMain.Controls.Add(slTmp);
this.intStepValue += 25;
slTmp = null;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
this.panViewScheduleMain.Height = this.intStepValue;
--
Mark Arteaga, MVP
info_[at]_markarteaga_[dot]_com
Mark Irvine said:
Mark,
Many thanks for your reply. Here is the code I'm using:
private void frmViewSchedule_Load(object sender, System.EventArgs e)
{
this.intStepValue = 0;
try
{
XmlNodeList xnlJobs =
this.mScheduling.GetAllUnchangedDetails(JobPriority.High);
for(int i = 0; i < xnlJobs.Count; i++)
{
ScheduleLabel slTmp = new ScheduleLabel(0, this.intStepValue,
this.panViewScheduleMain.Width, 20,
Convert.ToInt32(xnlJobs
.Attributes["index"].Value),
xnlJobs["job_properties"].Attributes["housenumber"].Value + " " +
xnlJobs["job_properties"].Attributes["housenumbersub"].Value + " " +
xnlJobs["job_properties"].Attributes["streetaddress"].Value + " " +
xnlJobs["job_properties"].Attributes["postcode"].Value,
(xnlJobs["job_response"]["job_response_details"] != null) ?
xnlJobs["job_response"]["job_response_details"].Attributes["description"]
..Value : "N/A", JobPriority.High, this.lblJobDetails);
this.panViewScheduleMain.Controls.Add(slTmp);
this.intStepValue += 25;
slTmp = null;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
this.panViewScheduleMain.Height = this.intStepValue;
}
The ScheduleLabel control is as follows:
public class ScheduleLabel : System.Windows.Forms.Control
{
private int intX;
private int intY;
private int intWidth;
private int intHeight;
private int intIndex;
private string strSummary;
private string strFullDetails;
private Label lblFullDetails;
private JobPriority jpPriority;
public ScheduleLabel(int intX, int intY, int intWidth, int intHeight, int
intIndex, string strSummary, string strFullDetails, JobPriority jpPriority)
: this(intX, intY, intWidth, intHeight, intIndex, strSummary,
strFullDetails, jpPriority, null)
{
}
public ScheduleLabel(int intX, int intY, int intWidth, int intHeight, int
intIndex, string strSummary, string strFullDetails, JobPriority jpPriority,
Label lblFullDetails)
{
this.intX = intX;
this.intY = intY;
this.intWidth = intWidth;
this.intHeight = intHeight;
this.intIndex = intIndex;
this.strSummary = strSummary;
this.strFullDetails = strFullDetails;
this.lblFullDetails = lblFullDetails;
this.jpPriority = jpPriority;
InitializeComponent();
}
public override string Text
{
set
{
base.Text = value;
Invalidate();
}
}
public string Summary
{
get
{
return this.strSummary;
}
}
public string FullDetails
{
get
{
return this.strFullDetails;
}
}
public int JobIndex
{
get
{
return this.intIndex;
}
}
private void InitializeComponent()
{
base.Location = new Point(this.intX, this.intY);
switch(this.jpPriority)
{
case JobPriority.High: this.BackColor = Color.Purple;
base.ForeColor = Color.White;
break;
case JobPriority.AM: this.BackColor = Color.Purple;
base.ForeColor = Color.White;
break;
case JobPriority.PM: this.BackColor = Color.Purple;
base.ForeColor = Color.White;
break;
default: this.BackColor = Color.Purple;
base.ForeColor = Color.White;
break;
}
base.Width = this.intWidth;
base.Height = this.intHeight;
base.Text = this.strSummary;
base.Click += new EventHandler(ScheduleLabel_Click);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
protected override void OnPaint(PaintEventArgs pe)
{
Graphics gr = pe.Graphics;
SolidBrush b = new SolidBrush(ForeColor);
gr.DrawString(base.Text, base.Font, b, 5, 2);
b.Dispose();
}
private void ScheduleLabel_Click(object sender, EventArgs e)
{
if(this.lblFullDetails != null)
{
this.lblFullDetails.Text = this.strFullDetails;
}
}
}
Mark
Mark Arteaga said:
I don't have problems resizing a panel. Post some sample code..it may
help a bit to pin point the problem.
--
Mark Arteaga, MVP
info_[at]_markarteaga_[dot]_com
:
Hi,
I am adding some labels dynamically to a panel. After all the label have
been added, I have calculated a new height for the panel. However
when
I
try to change the size of the panel, it remains at the size specified in
design view.
Is this not possible or am I missing something?
Mark