|
Try something like this:
public partial class Form1 : Form
{
List<button> buttons = new List<button>();
int counter = 0;
int maxButtons = 10;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
if (counter < maxButtons)
{
Point loc = new Point();
buttons.Add(new Button());
loc.X = ClientRectangle.X + (counter * 50);
loc.Y = ClientRectangle.Y + (counter * 50);
buttons[counter].Location = loc;
buttons[counter].Name = "Input name with some variable?";
buttons[counter].Click += new EventHandler(ButtonClickEvent1);
this.Controls.Add(buttons[counter]);
counter++;
}
else
{
throw(new Exception("Too many buttons"));
}
}
catch (Exception ex)
{
MessageBox.Show("A system error ocurred:\n" + ex.Message, "System Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
void ButtonClickEvent1(object sender, EventArgs e)
{
}
void ButtonClickEvent2(object sender, EventArgs e)
{
}
}</button></button>
|
|
|
|
|
Hi “High Octane”
YES YOU CAN! Been there and done it!
I am also a NEWB, I am also new to pasting replies on the code-project.
If (matter.resolved==false)
{
Read on!
}
I am assuming you are want to use the return/enter key to move from one textbox to another but validating the data that has been entered.
A group of textboxes for example? with the "Type in data then press enter" option?
I am not sure how you are validating your data but assume that you use the “Causes validation” property of the textbox. Personally I have a separate validation method fired by the leave event of the textbox.
I also use a keydown event for the same textbox.
In that event I call the "SelectNextControl" method once the return key was pressed.
The "SelectNextControl" method does what it says on the tin, but There are five parameters to it.
These are:-
Ctl
The Control at which to start the search.
forward
true to move forward in the tab order; false to move backward in the tab order.
tabStopOnly
true to ignore the controls with the TabStop property set to false; otherwise, false.
nested
true to include nested (children of child controls) child controls; otherwise, false.
wrap
true to continue searching from the first control in the tab order after the last control has been reached; otherwise, false.
Return Value
true if a control was activated; otherwise, false.
If you using a few textboxes then generate two event handlers one for keydown and one for leave and connect each textbox to the SAME EVENT HANDLER and use “case statements” switched from the name of the textbox. I can show you how to do this if necessary(just post a reply) I have about a dozen textboxes on one form and use ONE “Leave event” handler to handle EVERY ONE OF THEM and the return key can move between them.
I use the leave event to validate and enter the data into the program.
I use the keydown event is to detect if a key is down (crazy that eh!)
I have several textboxes and the use exactly the same leave and keydown event handlers, in the case below "tbxUpper"
private void tbxUpper_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Return)
{
TextBox tbx = (TextBox)sender;
SelectNextControl(tbx, true, true, true, true);
}
}
the above event actually fires every time a key is presses in a text box but the "if statement" looks for the return key. when the return key is pressed a textbox called tbx is generated and copied from sender then the next control is selected.
I don't know if this actually helps you.
If you need furthur help post a reply "and then hit Enter"!!
|
|
|
|
|
Could someone help out. I'm bulding a windows application that uses a skin instead of the form border that windows provides. Everything is going well except for my bosses specs. I am suppose to map the area on the skin that needs to be an onclick event. Kind of like an html and javaScript where your able to map a certain section of an image and make it a clickable link.
|
|
|
|
|
A transparent panel?
hmmm pie
|
|
|
|
|
Yep tried that. And I would think that it would work but it puts a black box over my image. I even tried to set the transparencyKey and that just cut a hole through my app. But in idea a transparent panel should work. Any thoughts?
|
|
|
|
|
I tried with a background image and the following worked fine:
this.panel1.BackColor = System.Drawing.Color.Transparent;
this.panel1.Click += new System.EventHandler(this.panel1_Click);
So panel with a background image instead of a pisture box would work fine.
hmmm pie
|
|
|
|
|
ok well my app is a little different. here a small sample of the app.
//this is my overloaded constructor
//gets loaded when the form is first Initialized
public HighCapacity(Skins sk) {
// I put the panel before the InitializeComponent() to get it to load.
// everything will need to be loaded dynamically
InitializeComponent();
//sets the border syle to none to I can add my own
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
//menuOff is a PictureBox that displays as the form
this.menuOff.Image = new Bitmap(sk.DayMenuSkin);
this.menuOff.SizeMode = PictureBoxSizeMode.CenterImage;
this.menuOff.SizeMode = PictureBoxSizeMode.StretchImage;
this.ClientSize = new Size(800, 600);
//set the background of menuOff
if (sk.BackgroundSkinType == "COLOR") {
//this.BackColor = Color.FromArgb();
} else if (sk.BackgroundSkinType == "IMAGE") {
this.menuOff.BackgroundImage = new Bitmap(sk.BackgroundImage);
} else {
this.BackColor = Color.Black; ;
}
this.menuOff.SizeMode = PictureBoxSizeMode.AutoSize;
this.Controls.Add(this.menuOff);
}
|
|
|
|
|
this.menuOff.Controls.Add(this.panel1);
Visual studio is a bit silly when it comes to moving the transparent panel over the image as it resets the above to add it to the form instead which is why it gives a black box.
hmmm pie
modified on Monday, February 23, 2009 6:22 AM
|
|
|
|
|
That did it lol. Thanks allot dude!!!!!
|
|
|
|
|
Hey.
I'm trying to create a client which responds to specific packets. The idea is, i'm going to have a large array of struct "packet" which stores information such as, the type of packet, the length of the sent packet, and a corresponding function it should call.
I know in C++ you can parse functions as parameters quite easily, or with some coding. However, in C# you need to use either delegate functions, or use the Reflection.MethodInfo methods.
The delegate functions may work, but the code to setup each row for my array would be extremely long and rather messy. I tried using the MethodInfo method instead, but the functions i'll be calling are marked with unsafe , and so my byte* parameter can't be passed through as an object in the object[] params :\
Is there any other method I could use to automate this system? Here's a snippet of what I mean:
_packetDB[++i] = new Packet() { type = 0x73, len = 11, func = "authok" };
Where "authok" is a function in a class foo . (When the packet is received, it will search for packet 0x73, and send the byte* data, the length into the function func )
Any help would be greatly appreciated.
Thanks
|
|
|
|
|
You should be using delegates. In general, its best to avoid the use of unsafe code or PInvoke, whenever possible. For your scenario, you should only need to do the following:
unsafe delegate void PacketHandler(byte* data, int length);
struct Packet
{
int type;
int len;
PacketHandler func;
}
void CreatePacket()
{
Packet packet = new Packet
{
type = 0x73,
len = 11,
func = AuthOK
};
}
unsafe void PacketProcessor(Packet packet)
{
byte* data = GetPacketData(packet.type);
packet.func(data, packet.len);
}
unsafe void AuthOK(byte* data, int len)
{
}
|
|
|
|
|
Oh! I always thought you had to define delegation functions as new DelegateFunction(FunctionToCall);
Thanks a lot, you're a life-saver. This should make the system work much, much better
|
|
|
|
|
Glad to be of service.
|
|
|
|
|
I have a list box in my app and i want it to autoscrol downward so it would always show the last item added.
Thank you
|
|
|
|
|
I think you have to do it manually. After adding an item to the end, call EnsureVisible[^].
|
|
|
|
|
didn't quite catch that... can u be more specific with the code?
|
|
|
|
|
Something like this:
int index = listBox.Items.Add("New item");
listBox.EnsureVisible(index);
[EDIT: Wait!! I was thinking of ListView instead of ListBox. Sorry! I'm looking into it right now.]
|
|
|
|
|
Found it!! Use the TopIndex[^] property of the ListBox control.
[EDIT: Oops, Luc beat me to it. ]
|
|
|
|
|
Hi,
whenever you change the number of items, do a myLB.TopIndex=myLB.Items.Count-1;
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:31 AM
|
|
|
|
|
|
You're welcome.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
After hours of searching I finally got this far and I'm not getting any errors
from this code. However I'm getting a black image. Is there something amiss here. I need to get access to this image regardless of wether it's visible on the physical montior or not and I'm assuming this may be the best way.
IHTMLElement test = (IHTMLElement)webBrowser1.Document.Images[i].DomElement;
IHTMLElementRender testRender = (IHTMLElementRender)test;
int hScreen = GDI.CreateCompatibleDC(this.CreateGraphics().GetHdc());
testRender.DrawToDC((IntPtr)hScreen);
int hCompDC = GDI.CreateCompatibleDC((IntPtr)hScreen);
int nWidth = webBrowser1.Document.Images[i].ClientRectangle.Width;
int nHeight = webBrowser1.Document.Images[i].ClientRectangle.Height;
int hBmp = GDI.CreateCompatibleBitmap((IntPtr)hScreen, nWidth, nHeight);
int hOld = GDI.SelectObject((IntPtr)hCompDC, (IntPtr)hBmp);
GDI.BitBlt((IntPtr)hCompDC, 0, 0, nWidth, nHeight, (IntPtr)hScreen, 0, 0, GDI.SRCCOPY);
GDI.SelectObject((IntPtr)hCompDC, (IntPtr)hOld);
GDI.DeleteDC((IntPtr)hScreen);
GDI.DeleteDC((IntPtr)hCompDC);
Image img;
pictureBox2.Image = Bitmap.FromHbitmap((IntPtr)hBmp);
|
|
|
|
|
Hi again,
I'm trying to add a little fuction to my app. I have a form for navigating through rows in a database table. All fields (textboxes) are readonly except one, which is a field I want the user to use to go directly to a certain row in the db. All this happens when to user presses the tab button and calls the Validated method of the textbox. How would I go about that exactly? textbox name is txtClientCode , the data in the table is loaded in m_dtClientInfo data table, and data adapter is m_daClientInfo. Database is a MS Access OleDB.
Anyone have a link to a good tutorial on querying and stuff in c#? I checked the articles overhere but didn't find anything! Thanks a lot for your patience with a newb
Yup, I'm a NEWB
|
|
|
|
|
So, when your user tabs out of that specific control, you want to fill the other text boxes with the data at that specific row index? Something like this could do it:
private void txtClientCode_Validated(object sender, EventArgs e)
{
int rowIndex = -1;
if(!int.TryParse(txtClientCode.Text, out rowIndex))
return;
DisplayClientInfo(rowIndex);
}
private void DisplayClientInfo(int rowIndex)
{
DataRow row = m_dtClientInfo.Rows[rowIndex];
txtFirstName.Text = (string)row["FirstName"];
} I hope this helps
|
|
|
|
|
I finally tried it out like this and it works:
private void txtClientCode_Validated(object sender, EventArgs e)
{
try
{
OleDbDataAdapter l_daCCSearch = new OleDbDataAdapter(
"SELECT * from ClientFile WHERE ClientCode = '" + txtClientCode.Text + "'", m_connection);
DataTable l_dtCCSearch = new DataTable();
l_daCCSearch.Fill(l_dtCCSearch);
txtClientCode.Text = l_dtCCSearch.Rows[0]["ClientCode"].ToString();
txtAdress.Text = l_dtCCSearch.Rows[0]["Adress"].ToString();
txtCity.Text = l_dtCCSearch.Rows[0]["City"].ToString();
txtCompanyName.Text = l_dtCCSearch.Rows[0]["CompanyName"].ToString();
txtContactName.Text = l_dtCCSearch.Rows[0]["ContactName"].ToString();
txtCountry.Text = l_dtCCSearch.Rows[0]["Country"].ToString();
txtEmail.Text = l_dtCCSearch.Rows[0]["Email"].ToString();
txtFax.Text = l_dtCCSearch.Rows[0]["FaxNumber"].ToString();
txtPhone.Text = l_dtCCSearch.Rows[0]["PhoneNumber"].ToString();
txtPostalCode.Text = l_dtCCSearch.Rows[0]["PostalCode"].ToString();
txtProvince.Text = l_dtCCSearch.Rows[0]["Province"].ToString();
txtTaxCode.Text = l_dtCCSearch.Rows[0]["TaxCode"].ToString();
rtxtNotes.Text = l_dtCCSearch.Rows[0]["Notes"].ToString();
}
catch (IndexOutOfRangeException)
{
DialogResult result;
result = MessageBox.Show("Aucune entrée correspondante à votre requête n'a été trouvée.", "Erreur");
if (result == DialogResult.OK)
{
this.ShowCurrentRecord();
}
}
}
Thanks a lot you pointed me in the right direction
Yup, I'm a NEWB
|
|
|
|