|
Thank you Xmen and Dave,
Unfortunately I'm tied up with Visual Studio Architect 2003 NET 1.1, yep 2003. For projects up until now it has been excellent. I'll have to invest in vs 2005 or 2008 and a new box. I chose Dave's "Not recommended" approach that passes Form1 to Form2's constructor. Since Form2 is permanently bound to Form1 it will be ok. For the moment. I can see problems in future though. Thanks again, I really enjoyed sharing all this.
Anthony
|
|
|
|
|
Don't give up on the proper way. It can be done in 1.1. I think the only difference is you can't use the Generic event handler for your delegate so you'll need to create your own delegate.
I don't have 1.1 (I'm using 2008 where the lowest I can target is 2.0). This should work though.
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private Button button1;
private IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
button1 = new Button();
SuspendLayout();
button1.Location = new Point(13, 13);
button1.Text = "Show Form2";
button1.Click += new EventHandler(this.button1_Click);
Controls.Add(this.button1);
ResumeLayout(false);
}
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.UpdateText += new Form2.UpdateTextEventHandler(form2_UpdateText);
form2.ShowDialog();
form2.UpdateText -= form2_UpdateText;
form2.Dispose();
}
void form2_UpdateText(string text)
{
Text = text;
}
}
using System;
using System.ComponentModel;
using System.Windows.Forms;
public class Form2 : Form
{
public delegate void UpdateTextEventHandler(string text);
public event UpdateTextEventHandler UpdateText;
public Form2()
{
InitializeComponent();
}
private TextBox textBox1;
private Button button1;
private IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
textBox1 = new System.Windows.Forms.TextBox();
button1 = new System.Windows.Forms.Button();
SuspendLayout();
textBox1.Location = new System.Drawing.Point(12, 12);
button1.Location = new System.Drawing.Point(12, 38);
button1.Text = "Update";
button1.Click += new System.EventHandler(this.button1_Click);
Controls.Add(this.button1);
Controls.Add(this.textBox1);
ResumeLayout(false);
PerformLayout();
}
private void button1_Click(object sender, EventArgs e)
{
OnUpdateText(textBox1.Text);
}
protected virtual void OnUpdateText(string text)
{
UpdateTextEventHandler eh = UpdateText;
if (eh != null)
eh(text);
}
}
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)
|
|
|
|
|
|
call Refresh() of that control to redraw
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Hi
i want to add multiple controls to my form at runtime, for example, i have a single button on my form, when i click this button, the second button add to my form, again, when i click on first button, the third button add to my form and so on, this code is something like this :
private void button3_Click(object sender, EventArgs e)
{
Button btn = new Button();
btn.Location = new Point(this.button3.Location.X + 80, this.button3.Location.Y);
this.Controls.Add(btn);
}
but the above code add only the first button at runTime and when i click again on button3 (in this example), the third button does not add to form. i think that it's couse by name of the controls which being create and it should have dynamic name for that control.
can anybody has experience in this issue ?
how to solve my problem ?
Thanks
|
|
|
|
|
Looks like your building buttons on top of each other.
Isn't it always going to set the location to the same place for every button?
|
|
|
|
|
I would suggest:
1. Finding the previously added button and setting the new X relative to that through iteration/foreach.
2. Referencing the last control in the Controls list (might be the last one) using the length/count of the list.
modified on Sunday, February 22, 2009 9:12 AM
|
|
|
|
|
Thanks Member 3493799
but i think beacuse the third control has a same name with second control, it does not create third control.
|
|
|
|
|
Set the name property different for each control added.
The word "politics" describes the process so well: "Poli" in Latin meaning "many" and "tics" meaning "bloodsucking creatures."
जय हिंद
|
|
|
|
|
You are not giving the new button created a click handler.So it does not know what to do when clicked.
|
|
|
|
|
Hi,
every time you click button3 you are creating and adding a new button. That is fine, except:
1. all new buttons are at the same location, so you will only see one of them.
2. none of them will do anything when clicked, since you did not do any btn.Click+=...
BTW:
1.the code to add controls at run-time can be identical to the code Visual Designer adds to your
<myform>.Designer.cs file when adding a control at design-time.
2. the Name property of a Control is often not important at run-time; the Designer uses it at design-time.
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
|
|
|
|
|
Getting compile (Overwritten area/contains Object field @ offset 21)
I want a string that is of length 11 (sender) and a string that is of length 23 (message).
Any help is appreciated; I cant see the problem.
[StructLayout(LayoutKind.Explicit, Pack = 1, Size = 66, CharSet = CharSet.Ansi)]
public struct chat
{
[FieldOffset(0)]
public int packetType; //4
[FieldOffset(4)]
public int packetNumber; //4
[FieldOffset(8)]
public int packetSource; //4
[FieldOffset(12)]
public int packetDestination; //4
[FieldOffset(16)]
public short packetPort; // 2
[FieldOffset(18)]
public ushort packetInfoEnd; // 2
[FieldOffset(20)]
public byte dataId; // 1
[FieldOffset(21)]
public string dataSender; // 11
[FieldOffset(32)]
public byte dataPadOne; // 1
[FieldOffset(33)]
public string dataMessage; // 23
[FieldOffset(56)]
public short dataPart; // 2
[FieldOffset(58)]
public int dataEndCodeOne; // 4
[FieldOffset(62)]
public int dataEndCodeTwo; // 4
public chat(int dst, short port, string sender, string message)
{
packetType = 1192961;
packetNumber = 0;
packetSource = 0;
packetDestination = dst;
packetPort = IPAddress.HostToNetworkOrder(port);
packetInfoEnd = 43521;
dataId = 10;
dataSender = sender;
dataPadOne = 0;
dataMessage = message;
dataPart = 206;
dataEndCodeOne = 10209786;
dataEndCodeTwo = 6658;
}
}
|
|
|
|
|
Hi,
in .NET a string is a reference type, so a struct (or anything else) containing a string is actually containing a reference (similar to a pointer), which must and will be "naturally aligned", that is at an offset which is a multiple of 4 or 8.
If you must have the content of an array or even a string embedded inside the struct, you can try this:
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=32)]
public string dmDeviceName;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=15)]
public int[] data;
that effectively turns reference types into value types as far as storage allocation goes.
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
modified on Sunday, June 12, 2011 8:29 AM
|
|
|
|
|
Thank you! It worked perfectly! Very much appreciated
|
|
|
|
|
Just a note for anyone else who comes across this issue and sees this thread:
The solution provided by Luc does NOT WORK with LayoutKind.Explicit, it only works with LayoutKind.Sequential, and with the FieldOffset()'s removed (obviously).
This is the compiling + working code:
[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 66, CharSet = CharSet.Ansi)]
public struct chatOne
{
public int packetType;
public int packetNumber;
public int packetSource;
public int packetDestination;
public short packetPort;
public ushort packetInfoEnd;
public byte dataId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 11)]
public string dataSender;
public byte dataPadOne;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 23)]
public string dataMessage;
public short dataPart;
public int dataEndCodeOne;
public int dataEndCodeTwo;
public chatOne(int dst, short port, string sender, string message)
{
packetType = 1192961;
packetNumber = 0;
packetSource = 0;
packetDestination = dst;
packetPort = IPAddress.HostToNetworkOrder(port);
packetInfoEnd = 43521;
dataId = 10;
dataSender = sender;
dataPadOne = 0;
dataMessage = message;
dataPart = 206;
dataEndCodeOne = 10209786;
dataEndCodeTwo = 6658;
}
}
|
|
|
|
|
The blow code is one of the 4 billion different tries of mine to get this working without help.
The cookies just don't work. The session is not persistent because it doesn't send the original cookies with the next request.
I've read that sometimes they get jumbled because of issues with maybe a comma in the cookie, but I have no idea if that is the problem or how to fix it...
CookieContainer CC = new CookieContainer();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://example.com");
request.CookieContainer = CC;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
CC.Add(response.Cookies);
request = (HttpWebRequest)WebRequest.Create("http://example.com");
request.CookieContainer = CC;
HttpWebResponse response2 = (HttpWebResponse)request.GetResponse();
|
|
|
|
|
Can anybody help me at all?
|
|
|
|
|
I simply want to process sql statement from the background by opening a popup window. After the process I want to close the window by itself w/o any interaction from the user.
I added this code in the code behind but it ask for questions "Do you want to close the window?" I don't want confirmation.
Response.Write("<script language='javascript'> { self.close() }</script>");
Thanks
Dabsukol
|
|
|
|
|
A quick Google search[^] gave me a few ideas.
I didn't try it but maybe this[^] should do the trick.
|
|
|
|
|
this.Close(); Usually works for me, at least this is the command I always put in the close buttons.
Also, self is VB iirc, not C#. In C# you need to use this .
|
|
|
|
|
hello... i have a datagrid view which takes a query from the database and displayes some data. not is it possible to display the same datagridview contents in a report... ??? thankyou...
|
|
|
|
|
max.4u wrote: i have a datagrid view which takes a query from the database and displayes some data
Does your datagrid have a datatable as a datasource?
max.4u wrote: is it possible to display the same datagridview contents in a report
If it does, you can use that datatable (or dataset) as a source for Reporting Services or Crystal Reports
|
|
|
|
|
my datagridview has a dataset. i tried by adding the dataset to the crystal reports from the wizard and its showing the data in the dataset.
but all i need is that my dataset is having a query which shows only a part of the data rather than all the data in the database.
so i need a way to call the query from the dataset.. thankyou..
|
|
|
|
|
I'm writing a program that tracks a moving objects in a mpeg file. I'm using AForge.net. I'm new to c# and programming. I cannot get to play the video. For right now I want to play the video in a picture box and cature new and old video frame to compare the movements. Here is my code so far that does not work.
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
How do I get to play the video in the picture box?? }
private void button1_Click(object sender, EventArgs e)
{
videoSource = new FileVideoSource(videoFile);
//videoSource.
//videoSource.NewFrame += new AForge.Video.NewFrameEventHandler(video_NewFrame);
videoSource.Start();
}
private void video_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
{
Bitmap bitmap = eventArgs.Frame;
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
openFileDialog.Filter = "Video (.mpeg)|*.mpeg|(.avi)|*.avi|ALL Files (*.*)|*.*";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
videoFile = openFileDialog.FileName;
}
}
Help anyone please:kathsunil
Posts: 1
Joined: Wed Feb 18, 2009 11:56 am
Private message
|
|
|
|
|