|
With the advent of .NET back in 2002, forms became true objects; they have members and can expose properties. Simply give your form a member variable and/or property and set it before calling Show() or ShowDialog()
MyForm form = new MyForm();
form.IpAddress = IpAddressTextBox.Text;
form.ShowDialog(this);
You could do that in VB6, too, but the form handling was clunkier.
|
|
|
|
|
Hi friends,
I have two 2 Dimensional string array.I want to trim the null values in the array. coz i can't initialize the array length.
like
Function Getarray(string[,] str)
{
}
by default this array has 250 items
even if i pass 12 items.
str[i,4]
here row no should be varied
how can i trim the null values
|
|
|
|
|
Then why use an array? Why not a List?
|
|
|
|
|
I want to hide Header(ie. Displaying the URL of the Page) and Footer(ie. getting page number and the current date and time) while printing a webpage using c#.
Thanks in Advance
modified on Tuesday, October 6, 2009 6:26 AM
|
|
|
|
|
where is your web page???
in your windows application browser??? or
web application browser??? or
any other web browsers??
Rajesh B --> A Poor Workman Blames His Tools <--
|
|
|
|
|
|
The footer is added by IE (the browser), and you cannot change that with any code on the server. You can, however, change the settings in the client-application.
Look under the menu "File", "Page Setup"
I are Troll
|
|
|
|
|
Hi,
In C, i have:
typedef struct strct_Err
{
int iErr;
int iMsgCount;
char* pstructMsg[2048];
} StructErr;
StructErr foo();
C#: i have:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public unsafe struct strct_Err
{
public int iErr;
public int iMsgCount;
IntPtr pstructMsg;
}
[DllImport(MY_DLL, CharSet = CharSet.Ansi)]
public static extern strct_Err foo();
When i execute this, it crashs.
If i disable all ref to pstructMsg in C and C#, it works then i suppose that i do not correctly import pstructMsg
Could you help me ?
What is the good way to import this struct with pstructMsg ?
Thanks you
Allan
|
|
|
|
|
In your C program struct you have char* pstructMsg[2048]; which is a 2048 element array of char* . In your C# program you have IntPtr pstructMsg; . However you have not shown where you access these fields nor the code where the crash occurs. Can you provide some more details?
|
|
|
|
|
You could always use a StringBuilder in place of the IntPtr - remembering to allocate 2048 bytes to it beforehand.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
The C struct contains an inline array of 2048 pointers to strings. Your C# struct has only a single pointer.
Because large structs as return values are actually passed as "out" parameters, you will get a buffer overflow/stack corruption if the C# struct is smaller than the C struct.
Unfortunately C# supports inline arrays in structs only for primitive types, not for pointers/IntPtr. On 32-bit systems, you could use
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public unsafe struct strct_Err
{
public int iErr;
public int iMsgCount;
public fixed int pstructMsg[2048];
}
but on 64-bit systems the array would have to use long.
Here's how you would read the strings from the array:
strct_Err e = foo();
for (int i = 0; i < 2048; i++) {
string text = new string((sbyte*)e.pstructMsg[i]);
Console.WriteLine(text);
}
If the foo() function allocates the C strings, you'll also have to deallocate them.
That said, are you sure the C struct contains an array of pointers as error message? If it's just a "char pstructMsg[2048];" (string of length 2048, no pointers involved), use the StringBuilder solution Pete mentioned.
|
|
|
|
|
Hi,
MCALLAN wrote: char* pstructMsg[2048];
I would guess this is wrong, a message is probably not going to point to thousands of strings, I rather expect it wants one string with up to 2048 characters, hence it should read char text[2048];
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Luc Pattyn wrote: I rather expect it wants one string with up to 2048 characters, hence it should read char text[2048];
I tend to agree, which is why I framed my original comment the way I did. Perhaps when OP responds we will discover the truth.
|
|
|
|
|
My guess was that it wants a pointer to an array instead of the array itself. My C/C++ is little more than an orange-brown stain at this point so I'm not sure what the proper syntax would look like.
The latest nation. Procrastination.
|
|
|
|
|
I need help for the following purpose:
Suppose I have a tree view and there are various items there. When I right click on a item it will display a menu which contains dynamic options in the menu.
[I have tried by context menu strip. For my tree view I have chosen the contextmenustrip1. But problem is when i right click any where on the tree view it shows the menu with static items. But I need when i will right click on any node only at that moment it should appear with some option those are available in a listbox.(The list box is dynamic)]
|
|
|
|
|
Use the ContextMenuStrip.Opening event to modify the content of your menu.
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
|
|
|
|
|
Thanks for the help. Now I can make it dynamic. But How can I just do it only for selected node? I only want that when i will click to any node then it should display the menu. Otherwise it should not display the menu if i click any place of the tree view other than any node.
|
|
|
|
|
You can rebuild the context menu every time you change selected node and just display it
OR
As suggested use the opening event and rebuild before opeing based on the currently selected node.
You may also want to look into the hittest and mousedown to select the node when you right click on it. IIRC the right click does not select the node.
|
|
|
|
|
private void yourTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
((TreeView)sender).SelectedNode = ((TreeView)sender).GetNodeAt(e.Location);
}
|
|
|
|
|
|
|
Dears , Can any one tell me How i can use listbox in Datagridview using C#.net
|
|
|
|
|
Well you could have tried using Google; it took me less than one minute to find this[^].
|
|
|
|
|
Hi,
How to enable write permission for a folder , I googled internet for some sample programs, I got few programs but these were on the basis on Domain name and User name! I would like to know how this can be achieved on a standalone system ? Do we require Domain name and User Name for changing permission of a folder?
I have attached a small program of with this issue, kindly review it, it is executing but there is write permission is not enabled with this.
using System;
using System.IO;
using System.Security.AccessControl;
using System.Windows.Forms;
namespace FileSystemExample
{
class FileExample
{
public static void Main()
{
string DomainName = System.Environment.UserDomainName.ToString();
DomainName += @"\";
string AccountName = System.Environment.UserName.ToString();
DomainName += AccountName;
try
{
string folderName = @"C:\Inetpub\ftproot";
Console.WriteLine("Adding access control entry for "
+ folderName);
AddFileSecurity(folderName,DomainName,FileSystemRights.WriteExtendedAttributes, AccessControlType.Allow);
Console.WriteLine("Removing access control entry from "
+ folderName);
RemoveFileSecurity(folderName, DomainName,FileSystemRights.WriteExtendedAttributes, AccessControlType.Allow);
Console.WriteLine("Done.");
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
public static void AddFileSecurity(string folderName, string account,
FileSystemRights rights, AccessControlType controlType)
{
FileSecurity fSecurity = File.GetAccessControl(folderName);
fSecurity.AddAccessRule(new FileSystemAccessRule(account,
rights, controlType));
File.SetAccessControl(folderName, fSecurity);
}
public static void RemoveFileSecurity(string folderName, string account,
FileSystemRights rights, AccessControlType controlType)
{
FileSecurity fSecurity = File.GetAccessControl(folderName);
fSecurity.RemoveAccessRule(new FileSystemAccessRule(account,
rights, controlType));
File.SetAccessControl(folderName, fSecurity);
}
}
}
Mike
|
|
|
|
|
You can add write permissions for local groups as well. And i guess for the "BUILTIN"'s as well.
|
|
|
|