|
sequential structure code means no function inside right?
thanks for above comments.
|
|
|
|
|
Are you referring to System.Runtime.InteropServices.LayoutKind[^]
Just an example from something I'm currently looking at:
[StructLayout(LayoutKind.Sequential)]
private struct MIDIINCAPS
{
public ushort wMid;
public ushort wPid;
public uint vDriverVersion;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string szPname;
public uint dwSupport;
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6 ? Do you hate yourself ? (Christian Graus)
|
|
|
|
|
I got 5 label side by side and i have a textbox. The textbox value will need to input to the label 1 by 1 after the user click on the button to submit.
Example
protected void btnSave_Click(object sender, EventArgs e)
{
if (label1.text != "") Then
label2.Text = Textbox1.Text;
}
I know the logic for this method is wrong. Any advice?
|
|
|
|
|
Hi,
you could:
1. keep an int that counts the button clicks
2. give the five labels consecutive names (or tags), say label1..label5
3a. inside btnSave_Click() scan myForm.Controls for the Control with the right label# name
3b. alternative: hold an array, say Label[] labels=new Label[5]{label1,label2,...}; and use the counter as an index.
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
|
|
|
|
|
Do you have any sample coding on 3b for me to reference. Thanks.
|
|
|
|
|
It's very simple, why not try to do something yourself before asking someone to give you code ?
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
This is my coding
for (int i = 0; i < 6; i++)
{
List<string> vote = new List<string>();
vote.Add(TextBox1.Text);
if (i == 1)
{
lblvote.Text = (vote[0]);
break;
}
else if (i == 2)
{
lblvote1.Text = (vote[1]);
break;
}
else if (i == 3)
{
lblvote2.Text = (vote[2]);
}
else if (i == 4)
{
lblvote3.Text = (vote[3]);
}
else if (i == 5)
{
lblvote4.Text = (vote[4]);
}
}
Still got error...
|
|
|
|
|
ciqing wrote: vote.Add(TextBox1.Text);
whatever the content is, this statement only adds one thing.
BTW: "Still got error..." is not informative.
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
|
|
|
|
|
Hi all
I would like to popup an Outlook contact via a Click button. The "Popup action" works fine~
However, after the outlook contact comes up, the WinForm(Form1) seem stuck and hold ....
I can't move, minimize and maximize the WinForm ?????
Any body know what is the problem in here ??
Thanks
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace testing1
{
public partial class Form1 : Form
{
Outlook.Application oApp = new Outlook.Application();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void FindContactEmailByName(string firstName, string lastName)
{
Outlook.NameSpace outlookNameSpace = oApp.GetNamespace("MAPI");
Outlook.MAPIFolder contactsFolder = outlookNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts);
Outlook.Items contactItems = contactsFolder.Items;
try
{
Outlook.ContactItem contact = (Outlook.ContactItem)contactItems.Find(String.Format("[FirstName]='{0}' and " + "[LastName]='{1}'", firstName, lastName));
if (contact != null)
{
contact.Display(true);
}
else
{
MessageBox.Show("The contact information was not found.");
}
}
catch (Exception ex)
{
throw ex;
}
}
private void button1_Click(object sender, EventArgs e)
{
FindContactEmailByName("Tom", "Lee");
}
}
}
|
|
|
|
|
contact.Display opens the contact window as a dialog window due to which parent window is stuck. You can call the this function in another thread if you want your parent window to work normally.
Regards
Shajeel
|
|
|
|
|
WOW!! Thanks for your answer! it works perfect with Threading !!! ~
|
|
|
|
|
We know that in winform,we can use "Tab" key to move focus,and now I want to move focus when I pressed "Enter" key in C# code project, I had added this code section in my form source,but it doesn't work sometimes.How can I do?
protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
{
if (keyData == Keys.Enter)
{
SendKeys.Send("{TAB}");
}
return base.ProcessCmdKey(ref msg, keyData);
}
|
|
|
|
|
I haven't tried, but if key is enter, don't call base.ProcessCmdKey .
|
|
|
|
|
Hope this can help..
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Enter)
{
SendKeys.Send("{TAB}");
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
8.Kelvin()
{
while (!(the machine can program itself))
Wont_stop_coding = true;
}
|
|
|
|
|
It can be simplified like this:
8.Kelvin(){
Wont_stop_coding = true;
}
|
|
|
|
|
Hihi, thanks.
Nice coding
*12Code
|
|
|
|
|
I need to break entire method when I click cancel. But when I put break its break if else part only. How can I break entire method?
private void NT_FormClosed(object sender, FormClosedEventArgs e)
{
MessageBox.Show("Do you want to close the program?", "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question,MessageBoxDefaultButton.Button2); {
if(DialogResult == DialogResult.Yes)
{
Save(sender);
}
if (DialogResult == DialogResult.Cancel)
{
Break; :doh:
}
}
}
A S E L A
|
|
|
|
|
return;
|
|
|
|
|
No cannot. when i use return still same.its all the way close the application. i want to continue application running when user click cancel.
A S E L A
|
|
|
|
|
FormClosed event handler is too late to cancel form closing. Try FormClosing[^] event. You can use FormClosingEventArgs.Cancel property to cancel the form closing.
|
|
|
|
|
Hello everybody,
My application uses a ListView control to display a list of files. Everything works fine except that when I set the
View property of the ListView to View.List, the list appears but, here's[^] a screenshot of how it looks. I can't understand,
why the filenames are condensed and appended with a "...". I've searched
google and msdn, but couldn't found a solution for the problem. The Large Icon[^] and Details Views[^]
are working perfectly. Just the list view is misbehaving.
My second problem is regarding a BackgroundWorker. I have a BGWKR that I'm using to perform a database transaction.
Now the problem is that the user may close the form while the transaction is in progress.
To handle this, I added code to the form's closing event handler, to inform the user that a transaction is active and ask
him/her, whether to cancel it. If the user affirms, then a call to BGWKR.CancelAsync() is made. Here's the form_closing event.
private void WndSearchResults_FormClosing(object sender, FormClosingEventArgs e)
{
if (bgDatabaseSearcher.IsBusy)
{
if (MessageBox.Show(Resources.msgSearchActive_WindowClosing, "Question",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
e.Cancel = true;
return;
}
else
{
bgDatabaseSearcher.CancelAsync();
while (bgDatabaseSearcher.IsBusy)
Thread.Sleep(500);
}
}
}
Here's the BGWKR's Do_Work event
private void bgDatabaseSearcher_DoWork(object sender, DoWorkEventArgs e)
{
VFS virtualFS = new VFS();
foreach (ListEntry entry in imagesToSearch)
{
try
{
virtualFS.OpenConnection(Path.Combine(AppSettingsManager.ImagesDirectory, entry.imageDbPath));
foreach (VFSSearchTerm searchTerm in termsToSearch)
{
virtualFS.SearchVFS(searchTerm, searchOptions, SearchResultProcessor, entry.imageID);
if (bgDatabaseSearcher.CancellationPending)
{
virtualFS.CloseConnection(true);
return;
}
}
}
finally
{
virtualFS.CloseConnection(true);
}
}
}
However, the DoWork methods cancels gracefully if CancelAsync() is called from a button's click event handler.
Please help.
Thanks
Excuse me for buttin' in, but I'm interrupt driven.
modified on Monday, April 6, 2009 11:27 PM
|
|
|
|
|
Hi,
1.
there seems to be no easy solution.
This article[^] is probably the best approach, however I never tried it.
2.
I did not understand the problem; also the post is too wide for easy reading.
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
|
|
|
|
|
My apologies for the post being too much wide. I've reformatted it now.
Excuse me for buttin' in, but I'm interrupt driven.
|
|
|
|
|
Hi,
much better now.
I still don't see what your problem #2 is, you say it works??
I do have 3 comments:
1. assuming lViewSResultsBrowser is a ListView, you are not allowed to perform a Groups.Add() operation (or any other Control operation) on it since Controls are not thread-safe. Without an InvokeRequired/Invoke construct it may hang your GUI temporarily or forever.
2. IMO all that is required for the cancellation is a simple
if (bgDatabaseSearcher.CancellationPending) break;
since that will bring you in the finally block, hence close the connection and return.
3. I don't particularly like the loop while (bgDatabaseSearcher.IsBusy) Thread.Sleep(500); since it makes your GUI hang for as long as the BGW takes; you have made your GUI thread a slave of your background worker now, so if the BGW never terminates, your app is stuck while the user wanted it to exit. The minimum I would do is impose an upper limit.
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
|
|
|
|
|
Hi,
Thanks for your response.
Well, my problem is not that the BGWKR is not working. Infact, it's working perfectly.
My problem is that if I call CancelAsync() from FormClosing event, the Do_Work method never stops
execution and the .IsBusy property never becomes false. At the same time, the code inside the Do_Work
event seems to be jammed. I can say this as the if(CancellationPending) condition in the Do_Work event is never hit.
The very same architecture works flawlessely, it CancelAsync() is called from a button's click event handler.
Your 1st comment: That Groups.Add() call is nothing. I added it for testing purposes while debugging.
So don't worry about that. I know it's not a thread-safe operation and will remove it.
Your 2nd comment: Doing so will only get me out of the inner foreach loop. What about the outer one?
Your 3rd comment: That i'll replace with code to hide the form and then wait till the BGWKR finishes or a deadline is met.
Excuse me for buttin' in, but I'm interrupt driven.
|
|
|
|