|
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
|
|
|
|
|
|
helo... am too working on the same kind od project... and my project has a windows service whicl listens the client requests on a port and then sends the messages to the client.
the client has a form which has a login mod which when provided with the user and password it sends to the server and authenticates at the server and then sends back the result.
and the client also secretly monitors the websites and the applcations visited by the user and sends the activity to the server at a fixed duration and the server logs in the data in to a db.
it will b completed within 5 or 6 days.. and regarding the udp connection you have used are you deploying the sys in LAN or INTERNET ? if its in lan then tcp type of connection is recommeneded, ... request if any help needed.... bye
|
|
|
|
|
|
I'm not sure what you've got at the moment, but you could use something like:
Process proc = Process.Start("Stuff");<br />
proc.MainWindowHandle ...
maybe you can find something useful in proc.MainModule and proc.Modules
And if not, there's always FindWindow[^] and FindWindowEx[^] which should let you grab the windows your looking for.
EDIT: And conveniently, I think the question below has some code that uses FindWindowEx so if your unsure on how to use it, there it is.
My current favourite word is: Delicious!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
I don't have the titles for the child windows or their class names to use find window ex.How I recieved the child window that I have a handle to I used enum child windows.
|
|
|
|
|
Hi
Ok so i have only been playing with C# for 1 day, so it's probably just me who can't get it to work.
It's a very small program to take 3 inputs (a string, a number and a selected process name) then input the string a number of times into the selected process. For testing i have Notepad open and the application name is "a.txt - Notepad"
Now my problem is that it works perfectly if i simply put "a.txt - Notepad" into the code. But if i do
String a = "a.txt - Notepad"
and then proc.MainWindowTitle == a then it doesn't work
Form1.cs
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 System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using System.Collections;
namespace ting
{
public partial class frmMain : Form
{
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("User32.Dll", EntryPoint = "PostMessageA")]
static extern bool PostMessage(IntPtr hWnd, uint msg, int wParam, int lParam);
[DllImport("user32.dll")]
static extern byte VkKeyScan(char ch);
public frmMain()
{
InitializeComponent();
comboBox1.DataSource = ProcessValidation.ListAllApplications();
}
private void Form1_Load(object sender, EventArgs e) { }
private void StartButtonClick(object sender, EventArgs e)
{
const uint WM_KEYDOWN = 0x100;
string text = txtText.Text;
string tidx = txtTime.Text;
if (tidx == "") tidx = "1";
int tid = int.Parse(tidx);
string windowTitle = (string)comboBox1.SelectedItem;
//MessageBox.Show(windowTitle + "a.txt - Notepad");
Process[] procs = Process.GetProcessesByName("Notepad");
foreach (Process proc in procs)
{
MessageBox.Show(windowTitle);
if (proc.MainWindowTitle == windowTitle)//"a.txt - Notepad")
{
// get handle to Notepad's edit window
IntPtr hWnd = FindWindowEx(proc.MainWindowHandle, IntPtr.Zero, "edit", null);
for (int i = 0; i < tid; i++)
{
for (int z = 0; z < text.Length; z++)
{
PostMessage(hWnd, WM_KEYDOWN, VkKeyScan(text[z]), 0);
}
// Thread.Sleep(11000);
}
break;
}
}
}
private void closeButtonClick(object sender, EventArgs e)
{
this.Close();
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
Show();
WindowState = FormWindowState.Normal;
}
private void frmMain_Resize(object sender, EventArgs e)
{
if (FormWindowState.Minimized == WindowState)
Hide();
}
}
}
ProcessList.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
using System.ComponentModel;
using System.Diagnostics;
using System.Collections;
namespace ting
{
public static class ProcessList
{
public static ArrayList ListAllApplications()
{
StringBuilder sb = new StringBuilder();
ArrayList a = new ArrayList();
foreach (Process p in Process.GetProcesses("."))
{
try
{
if (p.MainWindowTitle.Length > 0)
{
a.Add(p.MainWindowTitle.ToString() + Environment.NewLine);
}
}
catch { }
}
return a;
}
}
}
Form1.designer.cs
namespace ting
{
partial class frmMain
{
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// <param name="disposing" />true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmMain));
this.btnStart = new System.Windows.Forms.Button();
this.btnClose = new System.Windows.Forms.Button();
this.txtText = new System.Windows.Forms.TextBox();
this.txtTime = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.panel1 = new System.Windows.Forms.Panel();
this.processValidationBindingSource = new System.Windows.Forms.BindingSource(this.components);
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.processValidationBindingSource)).BeginInit();
this.SuspendLayout();
//
// btnStart
//
this.btnStart.Location = new System.Drawing.Point(16, 16);
this.btnStart.Name = "btnStart";
this.btnStart.Size = new System.Drawing.Size(75, 23);
this.btnStart.TabIndex = 0;
this.btnStart.Text = "Start";
this.btnStart.UseVisualStyleBackColor = true;
this.btnStart.Click += new System.EventHandler(this.StartButtonClick);
//
// btnClose
//
this.btnClose.Location = new System.Drawing.Point(178, 16);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(75, 23);
this.btnClose.TabIndex = 1;
this.btnClose.Text = "Luk";
this.btnClose.UseVisualStyleBackColor = true;
this.btnClose.Click += new System.EventHandler(this.closeButtonClick);
//
// txtText
//
this.txtText.BackColor = System.Drawing.SystemColors.Menu;
this.txtText.Location = new System.Drawing.Point(16, 75);
this.txtText.Name = "txtText";
this.txtText.Size = new System.Drawing.Size(100, 20);
this.txtText.TabIndex = 2;
//
// txtTime
//
this.txtTime.BackColor = System.Drawing.SystemColors.MenuBar;
this.txtTime.Location = new System.Drawing.Point(153, 75);
this.txtTime.Name = "txtTime";
this.txtTime.Size = new System.Drawing.Size(100, 20);
this.txtTime.TabIndex = 3;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(5, 12);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(28, 13);
this.label1.TabIndex = 5;
this.label1.Text = "Text";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(142, 12);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(22, 13);
this.label2.TabIndex = 6;
this.label2.Text = "Tid";
//
// notifyIcon1
//
this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
this.notifyIcon1.Text = "KillerApp 1.0";
this.notifyIcon1.Visible = true;
this.notifyIcon1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.notifyIcon1_MouseDoubleClick);
//
// comboBox1
//
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(16, 130);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(237, 21);
this.comboBox1.TabIndex = 11;
//
// panel1
//
this.panel1.BackColor = System.Drawing.SystemColors.AppWorkspace;
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panel1.Controls.Add(this.label1);
this.panel1.Controls.Add(this.label2);
this.panel1.Location = new System.Drawing.Point(6, 45);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(255, 256);
this.panel1.TabIndex = 12;
//
// processValidationBindingSource
//
this.processValidationBindingSource.DataSource = typeof(ting.ProcessList);
//
// frmMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(269, 313);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.txtTime);
this.Controls.Add(this.txtText);
this.Controls.Add(this.btnClose);
this.Controls.Add(this.btnStart);
this.Controls.Add(this.panel1);
this.Name = "frmMain";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Kims Killer App";
this.Load += new System.EventHandler(this.Form1_Load);
this.Resize += new System.EventHandler(this.frmMain_Resize);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.processValidationBindingSource)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button btnStart;
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.TextBox txtText;
private System.Windows.Forms.TextBox txtTime;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.BindingSource processValidationBindingSource;
private System.Windows.Forms.Panel panel1;
}
}
|
|
|
|
|
Might the string include a newline or some extra spaces in the combobox ? You could try using the Trim() method or looking at the value in the debugger. Or you could use .Contains instead of ==
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
put breakpoint on that comparision line then you will be able to know what proc.MainWindowTitle hold...
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
|
|
|
|
|
I writing some application that in some point in my application i need to check something in the microsoft outlook.
I found that to do it i need to use Microsoft Interop Outlook ( Microsoft.Office.Interop.Outlook) and when office 2007 is install on the machine its not this Interop assembly exist in the GAC -
But i want also to give the user the option to use my application when he have office 2003 on his machine. In this case i don't have this assemble in the GAC and i don't know how to solve this problem ( how to install this interop and how to create this interop that will match office 2003 ).
|
|
|
|
|
You probably interop with 2003 using COM
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Yes, as i said before ... i need to interop with 2003.
I need to use COM - but to use this interop in C#.
How to do it ... ?
|
|
|
|
|