|
I know how to do that, but what I want to know is how to have the program catch the button being pressed.
|
|
|
|
|
Place the code to close the form between the curly braces.....
private void button1_Click(object sender, EventArgs e)
{
formwhatever.close();
}
This is fairly basic you know.
Maybe you need a beginners book ???
A craft is an enemy if not well learned.
|
|
|
|
|
Actually I found what I was looking for:
<br />
this.add_button.Click += new System.EventHandler(this.save_content);<br />
|
|
|
|
|
at least 3-4 articles popped up in "C# event handling" on Codeproject
It is worth the time reading through. 1-2 hour & you'll be fine....
|
|
|
|
|
You also need to wire your handler to the event, as in:
button.Click+=new EventHandler(button1_Clicked);
Make sure this line executes only once (you can do it where you create the Button).
In fact you can and often should program exactly the way Visual Designer does it for you
when you add a Control graphically; just have a look in the code generated by Visual itself!
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- 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 PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
That's actually how I found the needed code (looked at Visual's generated code)
|
|
|
|
|
There are alternatives, such as
- reading the documentation (MSDN, Google),
- reading some articles, maybe from CodeProject
- working your way through a book on either a programming language or Visual Studio.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- 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 PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
I want to put a lot of Controls like Button or UserControl in one Form, and let it scrollable.
My question is if the number of Controls is 1000 or more, can it be tolerant when refresh the Form on a normal PC? or is there any tip on scrollable Form, like dealing with visible Controls only, i don't know~
anyway, thx for your reply!
http://chinajuanbob.spaces.live.com/
|
|
|
|
|
Your best bet is to avoid such horrible UI. Why don't you add 1000 controls to a form and see how it behaves ? I suspect it will be OK.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
You could always use tabs to try and manage this ludicrous amount of controls.
Or you could dump them in a panel... panels have scroll bars right? Or am i just confused again.
Forms don't refresh unless they have to either, and even then they only redraw what is necessary, but in the case of dragging this monster around the screen... of course if you can't see the controls, they won't get drawn, and it won't be a problem. So you'll probably be fine.
My current favourite word is: PIE!
I have changed my name to my regular internet alias. But don't let the 'Genius' part fool you, you don't know what 'SK' stands for.
-The Undefeated
|
|
|
|
|
SK Genius wrote: ludicrous amount of controls
I approached such a beast very easily recently while prototyping a line editor for record layouts. I used EditLine controls composed of one TextBox for each column in a record layout, and added a Preview mode that bound the editor to an actual file, not just the record definition. Presto! MolassesEditor v 1.0!
Calling all South African developers! Your participation in this local dev community will be mutually beneficial, to you and us.
|
|
|
|
|
1000 Buttons, thats about 10 piano keyboards...
Will you play them with a single mouse?
-- modified at 7:09 Friday 30th November, 2007
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- 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 PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hello,
I'm trying embed an mp3 in my file, and when the program is run, it'll read all the bytes of the embedded mp3 and create the file in a temp folder, then I can play it with sound player.
Here's my code that doesn't work because of "Illegal characters in path"
File.WriteAllBytes(@"C:\temp\test.mp3", File.ReadAllBytes(mp3practice.Properties.Resources.test));
I'm guessing that I need to open a stream to the resource? Am I on the right track? Any help would be appreciated, thanks.
|
|
|
|
|
I think your gonna need a stream. To get on of those, use something like this:
Stream myStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("name of embedded resource");
I'm sure you can figure out how to save the stream to a file. And if you can't try searching google for "c# save stream to file"
My current favourite word is: PIE!
I have changed my name to my regular internet alias. But don't let the 'Genius' part fool you, you don't know what 'SK' stands for.
-The Undefeated
|
|
|
|
|
Here ya go. You can alter the file exists check to your own needs if you don't care about overwriting the existing file. Hope that helps.
const int size = 4096;
Assembly currentAssembly = Assembly.GetExecutingAssembly();
string[] resources = currentAssembly.GetManifestResourceNames();
foreach (string resourceName in resources)
{
if (resourceName.EndsWith(".mp3"))
{
string saveAsName = resourceName.Replace(GetType().Namespace, string.Empty).Remove(0, 1);
FileInfo outputFile = new FileInfo(saveAsName);
if (!outputFile.Exists)
{
FileStream outputStream = outputFile.OpenWrite();
Stream resourceStream = currentAssembly.GetManifestResourceStream(resourceName);
byte[] bytes = new byte[size];
int numBytes;
while ((numBytes = resourceStream.Read(bytes, 0, size)) > 0)
{
outputStream.Write(bytes, 0, numBytes);
}
outputStream.Close();
resourceStream.Close();
}
}
}
|
|
|
|
|
Hi,
How to get the caller information from phone? What are the requirments needed?
Please any one help me.
Thanks,
Gopal.S
|
|
|
|
|
How are you expecting your PC to connect to the call ? Are you writing code to run on a phone ?
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi Christian,
Thanks for your reply.
Yes, I need to connect with PC and store the incoming call information in database.
Regards,
Gopal.S
|
|
|
|
|
Buy a phone with caller ID ????
A craft is an enemy if not well learned.
|
|
|
|
|
Hi,
Search the internet for TAPI is the API that will have to work with
Hope that helped
Nassos
|
|
|
|
|
When does memory get disposed of in .NET? I have a function that updates folding areas on a text editor and wanted to know when the text editor control will be deleted.
void UpdateFolding()<br />
{<br />
try<br />
{<br />
if ((m_oTabControl.TabCount > 0) && (m_oZipFile != null))<br />
{<br />
TabPage l_oTabPage;<br />
l_oTabPage = m_oTabControl.TabPages[m_oTabControl.SelectedIndex];<br />
<br />
<br />
<br />
<br />
if ((l_oTabPage.Controls.Count > 0) && (l_oTabPage.Controls[0] is TextEditorControl))<br />
{<br />
TextEditorControl l_oTextEditor = null;<br />
l_oTextEditor = (TextEditorControl)l_oTabPage.Controls[0];<br />
l_oTextEditor.Document.FoldingManager.UpdateFoldings(String.Empty, null);<br />
TextArea textArea = l_oTextEditor.ActiveTextAreaControl.TextArea;<br />
textArea.Refresh(textArea.FoldMargin);<br />
l_oTabPage.Controls.Add(l_oTextEditor);<br />
} <br />
}<br />
<br />
}
|
|
|
|
|
RussBus wrote: When does memory get disposed of in .NET?
Whenever the Microsoft .NET garbage collection developers feel like it. If your lucky they documented how .NET garbage collection works. If your even luckier you may be able to find the documentation. If you are insanely lucky you might be able to understand it.
Good luck
|
|
|
|
|
led mike wrote: Whenever the Microsoft .NET garbage collection developers feel like it.
I was just about to say that
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
The text editor control will be deleted when the form it belongs to is deleted.
As the code that you posted doesn't have anything to do with that, I assume that you are talking about the reference that you declare in the method.
A reference is not the object itself, it's only a pointer to the object. Assigning the text editor control to the variable doesn't create a copy of the control, it only make the reference point to it. When the reference goes away, the object itself still remains.
Local variables in a method are allocated on the stack when the method is called. When you return from the method, the stack is returned to it's previous state, and the local variables are gone.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Hi all
i have implemented a small application in which a button is placed named addRow when user clicks tht button a row is added in a grid view,whever user clicks it row will be added to the existing gridview i have done this with the following code now the problem is when i refresh the page the row is added or when i click any server control the row is also added bt i dont want this i just want the row shud be added when the button name addRow is clicked only.
any help will be greatly appreciated.thanks in advance
Code: ( cpp )
1.
protected void Page_Load(object sender, EventArgs e)
2.
{
3.
if (!Page.IsPostBack)
4.
Session["dt"] = null;
5.
6.
}
7.
protected override void OnPreInit(EventArgs e)
8.
{
9.
base.OnPreInit(e);
10.
if (Request.Form["hf"] == "true")
11.
addGVRow();
12.
hf.Value = string.Empty;
13.
}
14.
15.
16.
private void addGVRow()
17.
{
18.
DataTable dt = (DataTable)Session["dt"];
19.
int counter = 0;
20.
if (dt == null)
21.
{
22.
dt = new DataTable();
23.
dt.Columns.Add("seq");
24.
}
25.
else
26.
counter = dt.Rows.Count;
27.
DataRow dr = dt.NewRow();
28.
dr[0] = counter + 1;
29.
dt.Rows.Add(dr);
30.
gv.DataSource = dt;
31.
gv.DataBind();
32.
Session["dt"] = dt;
33.
}
and on aspx page for the button
<asp:button id="btn" runat="server" text="Add" onclientclick="javascript:document.getElementById('hf').value='tr ue';return true;">
|
|
|
|