|
You do call Dispose() on images you no longer need, do you?
If that doesn't help, show us some code.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Aurigma.com has an extension to .NET (GraphicsMill) that allows creating and saving TIFF images with LZW compression. Besides saving memory, compression also speeds up loading, saving, and transmitting images.
|
|
|
|
|
Hello,
I have a stream witch are send directly on printer using IP adresse and port, I want to receive this stream ans save it on file : for exemple PCL.
Please help me to resolve this problem. thank you verry mutch.
|
|
|
|
|
hi, I've been trying all the ways to access controls on the mainform from a class but something is missing.By the way, access modifier of the controls I want to access are all Private and I want to access them using public properties and methods. Here is the situation, thanks for your help.
I don't want to make "high coupling", wanna access just a few controls.
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
public string buttontext //using either this
{
get { return this.btn1.Text; }
set { this.btn1.Text = value; }
}
public void button1Text(string txt) //or this
{
btn1.Text = txt;
}
}
public partial class masaCubuk : UserControl
{
public masaCubuk()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//accessing with this
MainForm frm = new MainForm();
frm.buttontext="sample";
//or with this
MainForm frm = new MainForm();
frm.button1Text("sample");
}
}
|
|
|
|
|
|
but it is not recommended and I wanna figure out how it is done with public properties and methods
|
|
|
|
|
It's done the same way, but with a property "in between"
|
|
|
|
|
So do it. The property get / set is the way to go, but your code fragment should work, pretty much. You presumably have frm.Show() or frm.ShowDialog() somewhere, so what's the problem?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
there is no frm.Show(), I'm just creating an instance of the mainform and trying to get or set the value of controls on the mainform
|
|
|
|
|
And the code you posted will do that - you just won't see the results if you don't show the form...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
teknolog123 wrote: something is missing
Is this the problem that you need help with? I'm can see a mistake in your code but before I bother typing in a full response can you let us know what issues you are having.
Alan.
|
|
|
|
|
Hi Alan,
briefly, I created a custom control and put it on the main form.During runtime the custom control is doing something and needing to write/change value of the controls on the mainform. This is where I get stuck. All I want is to access and set/get the mainform's control's values through public properties/methods without making their access modifiers public.Please see my first post for the code I use
thanks in advance
|
|
|
|
|
Ok,
I'm still guessing then. The custom control, masaCubuk, is a child of MainForm and I assume that btn1.Text on the visible instance of MainForm never changes.
If that is the issue then the reason the code does not work lies in these lines:
private void button1_Click(object sender, EventArgs e)
{
MainForm frm = new MainForm();
frm.buttontext="sample";
}
Here you intend to communicate with the existing MainForm but have created a new instance. What would be required to get this code fragment to work is a reference to the actual MainForm, i.e. the parent of masaCubuk. You could pass the reference as an argument to masaCubuk's constructor but doing so would introduce the tight coupling that you wish to avoid.
The accepted "loose coupling" technique is to have the main form access the custom control by subscribing to events exposed by the control.
MSDN's How To topic[^]
If you have never written an event this will seem like a lot of work but the code pattern is so standard that once learnt it is easily remembered.
Alan.
|
|
|
|
|
The solution to this is to raise an event in the control that the form subscribes to. This is how all the 'built in' controls work too. Example:
using System;
using System.Drawing;
using System.Windows.Forms;
public partial class FormMain : Form
{
MyControl myControl;
Button button;
public FormMain()
{
InitializeComponent();
myControl = new MyControl();
myControl.SetTextRequest += myControl_SetTextRequest;
button = new Button();
Controls.Add(button);
button.Click += button_Click;
}
void button_Click(object sender, EventArgs e)
{
myControl.PerformSetTextRequest("Button");
}
void myControl_SetTextRequest(object sender, EventArgs<string> e)
{
button.Text = e.Value;
}
}
public class MyControl : Control
{
public event EventHandler<EventArgs<string>> SetTextRequest;
protected virtual void OnSetTestRequest(EventArgs<string> e)
{
EventHandler<EventArgs<string>> eh = SetTextRequest;
if (eh != null)
eh(this, e);
}
public void PerformSetTextRequest(string text)
{
OnSetTestRequest(new EventArgs<string>(text));
}
}
public class EventArgs<T> : EventArgs
{
public EventArgs(T value)
{
Value = value;
}
public T Value
{
get;
private set;
}
}
|
|
|
|
|
thanks so much Dave, I wasn't expecting so much code.To be honest I didn't understand because I am new to C# and other than that, if this neeeds to be done for every control I want to access, then I will be facing a big challenge Anyway, it is really nice of you to write the code in detail.I think I need to start from the beginning of event handling.
|
|
|
|
|
No problem.
Events are really simple once you grasp the concept. There are many articles/blog entries around that cover them, but most tend to get complex quickly.
I wrote an article here[^] to address this - you may find it useful. Take each example one by one and make sure you understand it thoroughly before looking at the next and you'll soon get it.
|
|
|
|
|
a much bigger thanks Dave, just as I started thinking that I was too stupid to understand the event handling issue, I red your experience about event handling and felt comfortable Finally there is a simple article + a demo project! what else a dummy wants? I will have a look at your article with an open mind, I have been struggling with the computer for 13 hours and started seeing illusions thanks again!
|
|
|
|
|
I need some ideas for my final project in c# related to database.
|
|
|
|
|
What kind of ideas you want?
|
|
|
|
|
like PIA flight Information System,or any shop or school or railway system
This is not my degrees final project,this is semester project.So it should be little smaal
|
|
|
|
|
Saba Minhas wrote: like PIA flight Information System,or any shop or school or railway system
So, you have many idea. Why you are not implementing one of them.
Saba Minhas wrote: This is not my degrees final project,this is semester project.So it should be little smaal
Don't go for develop all the things. Divide by module. Try to implement some of the main module.
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
I can't implement these ideas because my other classfellows are already implementing these ideas.
|
|
|
|
|
If you want something fairly simple, but usefull and expandable to any level of complexity you want, how about a to-do's list? Can be simple to start with, but expand to timers, reminders, assigned to user, GANT charts, etc.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
|
Hi,
Can someone please help me with this code?
10x
|
|
|
|