|
Class1 needs a reference to the instance of Form1 in order to manipulate that instance's controls (and other public properties and methods).
/ravi
|
|
|
|
|
How can I pass reference to the class1.cs file?
|
|
|
|
|
You don't pass the reference to a file, you pass it to the instance of the consuming class. With all due respect, I think you may be better off first understanding the basic concepts about programming before attempting this task.
/ravi
|
|
|
|
|
okay thanks. I will try read.
But I have tried to create instance to the class file. But it does not recognize the form object.
I dont know whether you can get me or not letme clear again.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using ourLibrary;
namespace MonitoringCheckList2009
{
public partial class BaseForm : Form
{
}
}
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace ourLibrary
{
public class LibraryClass
{
public void ShowLC(string dbTable, Control LstBox)
{
in form1.
}
}
}
If you dont understand pls let me know
Thanks
|
|
|
|
|
First of all, ShowLC() should accept a ListBox as its 2nd parameter, not a Control (unless you really want to pass a Control ).
From somewhere in your BaseForm do the following:
LibraryClass lc = new LibraryClass();
lc.ShowLC ("some string", this.listBox1);
/ravi
|
|
|
|
|
thanks a lot....
This is the ans I am finding.
Np i will read more.
|
|
|
|
|
Ravi has given you a solution that will work, but I don't believe it's the best or recommended way. Your Class1 should not be reliant on other objects to do it's stuff, so passing an object reference (a form, a control etc) in the constructor or elsewhere is not a good idea.
If the controls on Form1 need to be manipulated, it should be done from Form1 and nowhere else. If it needs to be in response to activity in Class1, then Class1 should raise relevant events and Form1 should subscribe to those and update the controls, play a fanfare or whatever.
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)
|
|
|
|
|
Thanks Dev But by useing Ravi's advice I can use my controls from anywhere I want. I just need to pass those controls by method, therest of the job will be done by that class1.
Isn't it helpfull?
|
|
|
|
|
Class1 is doing the job with controls which it doesn't own - a far from ideal situation. It's a quick and dirty solution, but I advise you to avoid it.
An event driven system is much better and not difficult. Simple example below:
using System;
public class Class1
{
public event EventHandler<MyEventArgs> MyEvent;
public void PerformMyMethod(string item)
{
OnMyEvent(new MyEventArgs(item));
}
protected virtual void OnMyEvent(MyEventArgs e)
{
EventHandler<MyEventArgs> eh = MyEvent;
if (eh != null)
eh(this, e);
}
}
public class MyEventArgs : EventArgs
{
private string _MyString;
public MyEventArgs(string myString)
{
_MyString = myString;
}
public String MyString
{
get { return _MyString; }
}
}
using System;
using System.Windows.Forms;
public partial class Form1 : Form
{
Class1 class1;
public Form1()
{
InitializeComponent();
class1 = new Class1();
class1.MyEvent += new EventHandler<MyEventArgs>(class1_MyEvent);
class1.PerformMyMethod("Hello World");
}
void class1_MyEvent(object sender, MyEventArgs e)
{
MessageBox.Show(string.Format(
"{0} from {1}!", e.MyString, sender));
}
}
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)
|
|
|
|
|
Thanks Deve...
I am totally new in C# but I have already develop a software for my office :P
With those poor logics. Now I am trying to read more and use best solution.
I am trying to understand your code.
Thanks for your effort.
|
|
|
|
|
Have a look at my article Events Made Simple[^] - it explains each line and builds step by step.
If you need more clarification, feel free to post back here
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)
|
|
|
|
|
Hi,
does anybody know of any information that suggests which version of the .NET framework is most popular?
We are looking to develop an application on .NET 3.5, but which version is most commonly installed?
thanks
Bluetooth Marketing
Bluetooth Advertising
|
|
|
|
|
|
According to my knowledge Framework version 2.0 is the best and stable. After all version 3.0 and 3.5 are extension of 2.0.
A DATAPOST COMPUTER CENTRE
(K.V Prajapati)
|
|
|
|
|
Be that as it may, how many systems have those but not 1.1?
|
|
|
|
|
Of course you are right. I meant the popular one.
A DATAPOST COMPUTER CENTRE
(K.V Prajapati)
|
|
|
|
|
Unless you need the latest new fangled whoopy doopy stuff, stick with 2.0 as that's a fair bet IMO.
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)
|
|
|
|
|
<blockquote class="FQ"><div class="FQA">DaveyM69 wrote:</div>stick with 2.0 as that's a fair bet</blockquote>
that was our thought, but does the proof that i'm looking for actually exist?
Bluetooth Marketing
Bluetooth Advertising
|
|
|
|
|
3.5 has a bunch of needless crap in it. (Linq, WPF, etc.)
The only worthwhile member of 3.5 is System.Collections.Generic.HashSet<T> , and even that's not very usable.
|
|
|
|
|
hi guys i am a informatic student and i am trying to bind php and c# with webservice (nusoap. so i have this php script:
<?
//incluimos la clase nusoap.php
require_once('lib/nusoap.php');
//declaramos el namespace
$ns="http://www.dominio.com/servidor.php";
//Setup del WSDL
$server = new soap_server();
$server->configureWSDL('webservice',$ns);
$server->wsdl->schemaTargetNamespace=$ns;
//Definimos la estructura de cada registro
$server->wsdl->addComplexType(
'registro',
'complexType',
'struct',
'all',
'',
array(
'nick'=>array('name' => 'nick', 'type' => 'xsd:string'),
'pass'=>array('name' => 'pass', 'type' => 'xsd:string'),
'telefono'=>array('name' => 'telefono', 'type' => 'xsd:string')
)
);
//Definimos la estructura de la matriz que usa los registros
$server->wsdl->addComplexType('estructura', 'complexType', 'array', '',
'SOAP-ENC:Array', array(),
array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:registro[]')),
'tns:registro');
//Registramos el método para devolver los valores de la tabla, en este caso es una consulta simple, mediante la cual se devuelven todos los registros de la tabla sin recibir ningún dato del cliente:
$server->register('obtenerdatos',array(),array('return'=>'tns:estructura')); //Definimos que lo que vamos a retornar es una matriz con la estructura "estructura
function obtenerdatos(){
$link = mysql_connect("localhost","root","213141");
mysql_select_db("ws");
$ssql_=mysql_query("select nick, pass, telefono from usuarios",$link)or die(mysql_error());
$numrows=mysql_num_rows ($ssql_);
$tabla=array();
for($x = 0; $x < $numrows; $x++) {
$tabla[]= mysql_fetch_array($ssql_);
}
return $tabla;
}
//llamamos al método service de la clase nusoap
$server->service($HTTP_RAW_POST_DATA);
?>
but i don't know how to get the data in c#, please help me.
It is too importan for me.
thanks
jahc the best
|
|
|
|
|
the class Timer is marvelous ... but asynchrone !!!
Can I don the same, without use horrible 'Sleep', in C#, but without the use of the API windows ??
Thanks a lot.
Bernard
|
|
|
|
|
either you wait some time (i.e. Thread.Sleep) or you organize a timer event.
What else could you possibly want?
FYI:
- don't call Sleep on the GUI thread;
- for delayed GUI stuff, use a System.Windows.Forms.Timer, that one ticks on the GUI thread.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I would like to build a custom control that would be exactly like the CStatic and CRectTracker are combined in MS Paint. What controls can be used to mimic this in .NET?
|
|
|
|
|
So I'm trying to workout a Chance on how often you would Die in a game with a push and every push had a 6% death with the Code I'm trying to use is
Death1 = (1 - Death) ^ HKill;
Yet you aren't allowed to use ^ on 'decimal' and 'decimal'.
I need to use decimals as 'int' wouldn't give a a true enough number to work with, any one know a formula that would do the above operation?
|
|
|
|
|
Hi,
From the MSDN documentation: "Binary ^ operators are predefined for the integral types and bool. For integral types, ^ computes the bitwise exclusive-OR of its operands. For bool operands, ^ computes the logical exclusive-or of its operands; that is, the result is true if and only if exactly one of its operands is true."
Exponentiation doesn't have its own operator; however there is Math.Pow (which works with doubles).
Decimals are used for quantities that need to be exact (i.e. currency amounts), not for dying game players.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|