|
Will try that
thanks
There are 10 types of people in the world, those who understand binary and those who dont.
|
|
|
|
|
Hello,
I'm looking for a simple sample (or a utility class) on how to build a workerthread for a windows forms application in .Net 1.1. But a search on the articles didn't help really.
Following I'd like to do:
-> Start the App and display a Form
-> Upon "start" button click start the thread (it is doing a couple of database and file operations, each of which must be completed entirely, before processing the next one)
-> The thread should be able to update a progress bar on the form and a couple of labels
-> When the user hits the "pause" button, the thread must complete the single operation it is currently working on and then wait until the user stops the whole thing completely or hits the "continue" button
Can anyone please point me into the right direction? Thanks in advance!
/matthias
I love deadlines. I like the whooshing sound they make as they fly by. [Douglas Adams]
|
|
|
|
|
Here is an application that I made for an interview that calculates prime numbers.
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections;
using System.Threading;
using System.IO;
namespace Primes
{
public class MainForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Button cmdDoit;
private System.Windows.Forms.ListBox lbPrimes;
private System.Windows.Forms.ProgressBar pbPrimes;
private System.Windows.Forms.Label lblValue;
Thread t;
public MainForm()
{
InitializeComponent();
}
[STAThread]
public static void Main(string[] args)
{
Application.Run(new MainForm());
}
#region Windows Forms Designer generated code
private void InitializeComponent() {
this.lblValue = new System.Windows.Forms.Label();
this.pbPrimes = new System.Windows.Forms.ProgressBar();
this.lbPrimes = new System.Windows.Forms.ListBox();
this.cmdDoit = new System.Windows.Forms.Button();
this.SuspendLayout();
this.lblValue.Location = new System.Drawing.Point(8, 64);
this.lblValue.Name = "lblValue";
this.lblValue.TabIndex = 3;
this.pbPrimes.Location = new System.Drawing.Point(8, 40);
this.pbPrimes.Name = "pbPrimes";
this.pbPrimes.TabIndex = 2;
this.lbPrimes.Location = new System.Drawing.Point(8, 96);
this.lbPrimes.Name = "lbPrimes";
this.lbPrimes.Size = new System.Drawing.Size(136, 290);
this.lbPrimes.TabIndex = 0;
this.cmdDoit.Location = new System.Drawing.Point(8, 8);
this.cmdDoit.Name = "cmdDoit";
this.cmdDoit.TabIndex = 1;
this.cmdDoit.Text = "Calculate";
this.cmdDoit.Click += new System.EventHandler(this.CmdDoitClick);
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(152, 398);
this.Controls.Add(this.lblValue);
this.Controls.Add(this.pbPrimes);
this.Controls.Add(this.cmdDoit);
this.Controls.Add(this.lbPrimes);
this.Name = "MainForm";
this.Text = "Primes";
this.Closing += new System.ComponentModel.CancelEventHandler(this.MainFormClosing);
this.Load += new System.EventHandler(this.MainFormLoad);
this.ResumeLayout(false);
}
#endregion
void MainFormLoad(object sender, System.EventArgs e)
{
}
void CmdDoitClick(object sender, System.EventArgs e)
{
Control.CheckForIllegalCrossThreadCalls = false;
t = new Thread(new ThreadStart(Calc));
t.Start();
}
void Calc() {
int count = 0;
int max = 1000000;
this.pbPrimes.Maximum = max;
this.pbPrimes.Value = 0;
ArrayList al = new ArrayList();
for (int x = 1; x <= max; x++) {
bool prime = true;
for (int y = 2; y < (x/2)+1; y++) {
if ((x % y) == 0) {
prime = false;
}
}
if (prime) {
al.Add(x);
count++;
}
pbPrimes.Value++;
lblValue.Text = pbPrimes.Value.ToString();
}
lbPrimes.DataSource = al;
FileStream fs = new FileStream("Primes.txt",FileMode.Create);
BufferedStream bs = new BufferedStream(fs);
StreamWriter sw = new StreamWriter(bs);
foreach (int num in al) {
sw.WriteLine(num.ToString());
}
sw.Close();
bs.Close();
fs.Close();
MessageBox.Show(count.ToString() + " Primes were found and written to Primes.txt");
}
void MainFormClosing(object sender, System.ComponentModel.CancelEventArgs e)
{
try {
t.Abort();
} catch (Exception ex) {
MessageBox.Show(ex.ToString() + " Thread could not be stopped");
}
}
}
}
There are 10 types of people in the world, those who understand binary and those who dont.
|
|
|
|
|
I’m looking for a book or website. I have an application this views several different graphic controls in windows within my MDI Form. I would like to create a nice application to for all these images. Several can be open at once. The mouse context and control is same for each, but the control functions can be different.
PS: I’m new to using forms. My past GUIs where written in MFC.
Thanks
Programmer
Glenn Earl Graham
Austin, TX
|
|
|
|
|
Hi,
I've my windows form application with Form1.h where i've implemented the graphic interface.
Then i've Myclass.h where i declare a class
#include "form1.h"
....
class Myclass{
public:
Myclass();
~MyClass();
void func();
void func2();
private:
...
}
and the myclass.cpp file where i implement the class.
Two problems:
1-Where must i have to put "Form1^ fr=gcnew Form1" declaration so that any method of myclass can see fr variable?
2-I want to put a condition in func() body that when button1(in the graphic interface of Form1.h) is clicked i do something. How can i write this condition?
Thank in advance for answers, regards.
|
|
|
|
|
Have you figured this out or still working on it?
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
1- For the first problem i don't find a solution so i change my code.
2- For the second problem i declare a flag variable that change its value then the button is clicked.
Bye.
|
|
|
|
|
Sounds like you got it taken care of. I was just running through some of the unanswered questions and just seeing if they were still an issue with the poster and if so, I could maybe help out.
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
I am developing an application which needs to be deployed using click once. We have 4 physical sites connected by a WAN link. I can deploy to a file server in each of these sites for local users to connect and update the app. However we have several roaming users which we do not want to update from site A when they are currently at site B etc. Does anybody know a way I can programatically change the update location for this app for each time it starts up.
|
|
|
|
|
Hi, i've a visualc++ project( window form application).
I've created a class in a cpp file ( and its .h file)with this simple structure:
class Myclass{
public:
Myclass();
~Myclass();
func1();
func2(int n);
private:
int n;
}; and i've implemented the functions.
Then i've my graphic interface composed by some form application.
This is one...Camlive.h
#pragma once
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
namespace WinCam {
public ref class Camlive : public System::Windows::Forms::Form
{
public:
Camlive(void)
{
InitializeComponent();
}
protected:
~Camlive()
{
if (components)
{
delete components;
}
}
private:
///
/// Required designer variable.
///
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
void InitializeComponent(void)
{
this->components = gcnew System::ComponentModel::Container();
this->Size = System::Drawing::Size(300,300);
this->Text = L"Camlive";
this->Padding = System::Windows::Forms::Padding(0);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
}
#pragma endregion
};
}
I want to use it and its components(like a button control or a textlabel) in Myclass. For example i want that func() of myclass can modify a textlabel of camlive.h.
When i try to make a new object of class Camlive( Camlive^ cml in Myclass, it returns a compile error.
How can i do?
Thanks, regards.
|
|
|
|
|
dodoxor wrote: I want to use it and its components(like a button control or a textlabel) in Myclass. For example i want that func() of myclass can modify a textlabel of camlive.h.
The buttons and labels, generally all controls, are private members by default. Change it to public.
dodoxor wrote: When i try to make a new object of class Camlive( Camlive^ cml in Myclass, it returns a compile error.
How can i do?
<br />
Camlive^ cml = gcnew Camlive();<br />
cml->ShowDialog();
P.S: you should include the Camlive.h header at the top of your class.
#include "Camlive.h"
|
|
|
|
|
I try but it returns some compiler errors...
#ifndef CAMOBJ_H
#define CAMOBJ_H
#include "Camlive.h"
//other include..
#define WIDTH (100)
#define HEIGHT (100)
class Camobj
{
public:
Camobj();
~Camobj(void);
void capture(void);
private:
camaddr_t camaddr;
Camlive^ cml;///compiler error
};
#endif
And in the camobj.cpp
#include "stdafx.h"
#include "Camobj.h"
using namespace System;
using namespace System::IO;
Camobj::Camobj()
{
cml=new Camlive();//compiler error
}
Camobj::~Camobj(void){
...
}
The compiler errors are:
...\Camobj.h(56) : error C2143: syntax error : missing ';' before '^'
...\Camobj.h(56) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
...\Camobj.h(56) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
...\Camobj.h(56) : error C3265: cannot declare a managed 'cml' in an unmanaged 'Camobj'
.\Camobj.cpp(15) : error C2065: 'cml' : undeclared identifier
.\Camobj.cpp(15) : error C2061: syntax error : identifier 'Camlive'
How can i relsolve it?
Thanks regards.
|
|
|
|
|
Hi Guys,
I am developing website that has button controls. When browsing it thru windows xp IE6 or IE7 the view is correct but when browsing it thru mac safari the button will show even I changed the properties to "transparent".
If you encountered this kind of issue I am hoping that you'll gonna share it with me.
Thanks in advance Guys.
Note: This message was mistakenly shared in this category
-- modified at 10:10 Monday 21st May, 2007
hifiger2004
|
|
|
|
|
Hi,
I am working on a project in Windows Forms VS 2005 .I want to use the report viewer control in this. I got some information on the net and implemented it in a sample project. It works absolutely fine.
I tried implementing it the same way in my project, it does not work.
What i am doin is i am adding a data source. On clicking on "Object" icon in data source wizard the assembly should be visible. But it doesn't appear in my final project. I tried finding out the difference in settings between the 2 projects.
In the references options of the project,in "Configuration properties", in "General" suboption the "Common lanuguage runtime support" option were different.
In the project in which the report viewer control works fine, the
"Common lanuguage runtime support" option is selected is ::
Pure MSIL Common Language Runtime Support(/clr::pure)
In my project I need to make is as
Common Language Runtime Support(/clr)
because I am using Win32 dlls in my project.
Please let me know what changes have to be made so that I ma able to view the assemblies in the wizard.
Thanx in advance.
shraddha
|
|
|
|
|
Hello,
I have a windows application. After exiting the application, I also want to kill the exe running. How to do this?
Please reply. Its urgent.
Thanks in advanced
Nana
|
|
|
|
|
Don't double post. I answered you in c# forum
|
|
|
|
|
Hi Friends,
I am using the following methods to bind the windows.combobox control. In this screen how to insert a value to 0 position of the list.
cboKeyword.DataSource = dsResult.Tables["tmpTable"];
cboKeyword.DisplayMember = "ProductKeyword";
cboKeyword.ValueMember = "PortalProductMasterID";
Keyword k = new Keyword();
k.KeywordID = "";
k.KeywordName = "<-Select Keyword->";
cboKeyword.Items.Insert(0, k);
It is not working.
Please Help
Thanks in Advance
Rameshkumar Thirumalaisamy
|
|
|
|
|
hi,
it seem that you are binding two different types to a single combobox.
first you bind the "tmpTable" with the columns "ProductKeyword" and "PortalProductMasterID" then you bind an object "Keyword". but from the code you provided, i don't see any similarity between the two - "tmpTable" and "Keyword". your existing "Keyword" class doesn't contain the properties you are trying to bind. what you should do is make the class "Keyword" comparable to the table you are trying to bind, i.e. add the properties "ProductKeyword" and "PortalProductMasterID" to you existing class - "Keyword".
hope this helps
reagards
|
|
|
|
|
Please Check It
cboKeyWord.Items.Add( new ListItem("<-Select KeyWord>-", "0"));
|
|
|
|
|
Hello All,
I want to catch scroll event of a list box in C#. I want to use two list box, and when one is scrolled the another should automatically be scrolled. What should I do for that.
Thanks.
|
|
|
|
|
Hallo,
I am trying to do the same thing. Did you manage to figure this out?
Thanks
There are 10 types of people in the world, those who understand binary and those who dont.
|
|
|
|
|
Hello smyer,
First you made your own scrolling listbox using this code :
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Runtime.InteropServices;
namespace myscrollList
{
class scrollList : System.Windows.Forms.ListBox
{
[Category("Action")]
//public event ScrollEventHandler Scroll = null;
private const int WM_HSCROLL = 0x114;
private const int WM_VSCROLL = 0x115;
public event ScrollEventHandler OnHorizontalScroll;
public event ScrollEventHandler OnVerticalScroll;
private const int SB_LINEUP = 0;
private const int SB_LINELEFT = 0;
private const int SB_LINEDOWN = 1;
private const int SB_LINERIGHT = 1;
private const int SB_PAGEUP = 2;
private const int SB_PAGELEFT = 2;
private const int SB_PAGEDOWN = 3;
private const int SB_PAGERIGHT = 3;
private const int SB_THUMBPOSITION = 4;
private const int SB_THUMBTRACK = 5;
private const int SB_PAGETOP = 6;
private const int SB_LEFT = 6;
private const int SB_PAGEBOTTOM = 7;
private const int SB_RIGHT = 7;
private const int SB_ENDSCROLL = 8;
private const int SIF_TRACKPOS = 0x10;
private const int SIF_RANGE = 0x1;
private const int SIF_POS = 0x4;
private const int SIF_PAGE = 0x2;
private const int SIF_ALL = SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS;
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetScrollInfo(
IntPtr hWnd, int n, ref ScrollInfoStruct lpScrollInfo);
private struct ScrollInfoStruct
{
public int cbSize;
public int fMask;
public int nMin;
public int nMax;
public int nPage;
public int nPos;
public int nTrackPos;
}
protected override void WndProc(ref System.Windows.Forms.Message msg)
{
if (msg.Msg == WM_HSCROLL)
{
if (OnHorizontalScroll != null)
{
ScrollInfoStruct si = new ScrollInfoStruct();
si.fMask = SIF_ALL;
si.cbSize = Marshal.SizeOf(si);
GetScrollInfo(msg.HWnd, 0, ref si);
if (msg.WParam.ToInt32() == SB_ENDSCROLL)
{
ScrollEventArgs sargs = new ScrollEventArgs(
ScrollEventType.EndScroll,
si.nPos);
OnHorizontalScroll(this, sargs);
}
}
}
if (msg.Msg == WM_VSCROLL)
{
if (OnVerticalScroll != null)
{
ScrollInfoStruct si = new ScrollInfoStruct();
si.fMask = SIF_ALL;
si.cbSize = Marshal.SizeOf(si);
GetScrollInfo(msg.HWnd, 0, ref si);
if (msg.WParam.ToInt32() == SB_ENDSCROLL)
{
ScrollEventArgs sargs = new ScrollEventArgs(
ScrollEventType.EndScroll,
si.nPos);
OnVerticalScroll(this, sargs);
}
}
}
base.WndProc(ref msg);
}
private void InitializeComponent()
{
this.SuspendLayout();
//
// scrolled
//
this.Size = new System.Drawing.Size(120, 95);
this.ResumeLayout(false);
}
}
}
After this .........
Drag your listbox on windows forms and than sync two listbox together using this.......
private void scrollList1_OnVerticalScroll(object sender, ScrollEventArgs e)
{
scrollList2.TopIndex = scrollList1.TopIndex;
}
private void scrollList2_OnVerticalScroll(object sender, ScrollEventArgs e)
{
scrollList1.TopIndex = scrollList2.TopIndex;
}
I hope this will work..........
nav_smec
|
|
|
|
|
Thanks
Will try this
There are 10 types of people in the world, those who understand binary and those who dont.
|
|
|
|
|
Hi There,
I'm having some trouble with CheckedListBoxes in my application. The application is written in C# in .NET 1.1. It's multi-tabbed, and on each tab there is an instance of my user control, which contains 6 combo's and 6 CheckedListBoxes.
The control works fine when you stay on a single tab, however when I switch tab and come back again, all the CheckedListBoxes still have their data, but they lose the CheckedItems collection, so they are all unchecked.
Has anyone come across this problem?
Thanks in advance,
modified 30-May-24 18:02pm.
|
|
|
|
|
Jim,
(I could wait til you get back from lunch.. but I think the code project needs to know as well )
I found the problem, its a known bug in .NET 1.1.
Documented here: http://support.microsoft.com/kb/833033
The problem only occurs when the checked list box is bound to a data table.
It looks like Microsoft's only solution is to maintain a collection of checked items and refill on tab switch (rubbish!). But I guess that is what we're going to have to do...
Rob.
|
|
|
|