473,388 Members | 1,298 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

C# working with dynamic controls through classes

Hi,

I just started using c# about a week ago and have run into a roadblock when trying to create a function class to reduce the size of my app.

here is my code:

Expand|Select|Wrap|Line Numbers
  1. private void NumericUpDown1_ValueChanged(object sender, System.EventArgs e) {
  2.  if (pts > 0) {
  3.   NumericUpDown1.Maximum = 5
  4.   NumericUpDown2.Maximum = 5
  5.   NumericUpDown3.Maximum = 5
  6.   NumericUpDown4.Maximum = 5
  7.   NumericUpDown5.Maximum = 5
  8.   if (NumericUpDown1.Value > NumericUpDown1LastValue) {
  9.    pts = pts - 1;
  10.   }
  11.   if (NumericUpDown1.Value < NumericUpDown1LastValue) {
  12.    pts = pts + 1;
  13.   }
  14.   NumericUpDown1LastValue = NumericUpDown1.Value;
  15.   lblPts.Text = pts.ToString();
  16.   if (pts == 0) {
  17.    NumericUpDown1.Maximum = NumericUpDown1.Value;
  18.    NumericUpDown2.Maximum = NumericUpDown2.Value;
  19.    NumericUpDown3.Maximum = NumericUpDown3.Value;
  20.    NumericUpDown4.Maximum = NumericUpDown4.Value;
  21.    NumericUpDown5.Maximum = NumericUpDown5.Value;
  22.   }
  23.   if (pts == 0) {
  24.    if (NumericUpDown1.Value < NumericUpDown1LastValue) {
  25.     pts = pts + 1;
  26.    }
  27.    NumericUpDown1LastValue = NumericUpDown1.Value;
  28.    lblPts.Text = pts.ToString();
  29.   }
  30.  }
  31.  
I have over 60 NumericUpDown controls that are handled by this handler, but each have very slight differences, so i've been using individual handlers like the one above to handle each one, and i've just been editing out the differences. if there is a way to make a generic function class that would be able to do this that basically just generalizes NumericUpDown1 and lblPts so i can drop them in as parameters it would be swell.
Sep 10 '07 #1
0 774

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Roy Lawson | last post by:
I want to enable the user to define parts of their user interface. I am developing an application that does some accounting functions (basicly the end user enters revenues for each account, and...
6
by: MikeY | last post by:
Hi Everyone, Does anyone know where I can get my hands on a sample with source code of a simple dynamic button control in C# Windows form. I am looking for a sample that uses a class library...
7
by: Andrew Robinson | last post by:
Given HTML text (likely from SQL), is there any method that could be employed to render server and/or custom controls that are contained inside of that text? I would be loading content from a...
8
by: jojobar | last post by:
Okay, I am trying to do is to test the webresource in 2.0 1. I created a new project with assembly name (and default assembly name) "Office". 2. I added the following to the AssemblyInfo.cs...
2
by: Sharon | last post by:
Hi all, When generating controls dynamically on a server event, control event does'nt work. Whats the problem? Thanks, Sharon.
2
by: Martin | last post by:
Hi, I need to create the html below with dynamic controls <span class="myclass"> <h3>text1</h3> <h4><span>Price <strong>text2</strong> | Duration <strong>text3</strong></span></h4> </span>
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
9
by: Tarscher | last post by:
hi all, I have this seemingly simple problem. I have lost a lot of time on it though. When a user selects a value from a dropdownlist (static control) a dynamic control is generated. I have...
3
by: =?Utf-8?B?U3ViYQ==?= | last post by:
I am using a asp page to dynamically create a stylesheet my asp page creates the following css element when i call the asp page my typing the url in the browser. My asp page works...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.