|
I think you cannot save the currage return functionality in a string.
Try Console.WriteLine("line1\nnewline2\nnewline3");
or
String str1 = "line1";
String str2 = "newline2";
String str3 = "newline3";
Console.WriteLine(str1 "\n" str2 "\n" str3 );
hope this helps
|
|
|
|
|
Use "\r\n" instead of just "\n"
|
|
|
|
|
|
|
Hi,
Option 1:
string str = "line1" + "\n" + "newline2" + "newline3";
Option 2:
String str = "line1 \n\r newline2 \n\r newline3";
Majid, Tell me if these does not work.
Regards,
Sugandh
|
|
|
|
|
non of them doesn't work Sugandh.
I wanna use it in header text of a column of DataGrid control.
|
|
|
|
|
What do you think "multi line strings" are?
For the String class, the character '\n' is handled exactly like an 'a' or '7'. It's just a character like any other. String itself doesn't have a concept of multi line!
So you'll have to tell us where you want to _use_ the string.
In a TextBox , the line separator is "\r\n".
In a RichTextBox , the line separator is "\n".
So depending on where you need the string the answers will be different.
mav
|
|
|
|
|
I wanna use it in the header text of a column of DataGrid control.
|
|
|
|
|
Then I would guess it is the DataGrid that strips the newlines.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
In this case I doubt that you'll succeed with any of these approaches.
You see, the DataGrid is responsible for drawing the column headers according to their current texts, but I don't think the developers took multiline headings into consideration.
That's why you get blanks where your not-printable characters ('\n', '\r') are.
In order to achive multiline headings you'd have to perform drawing of the DataGrid column headers by yourself (perhaps you're able to do this using P/Invoke, I'm not sure).
Anyway: My suggestion would be _not_ to use multiline headings. Headings are used to give the user a short information what the contents of a column are. You're not supposed to write lengthy texts there.
mav
|
|
|
|
|
I am trying to develop the following functionality. The user selects a button. In the on-click event I then want to bring up a new web page (small one) that contains a dropdowm list box. This list box would be bound to a data base. When the user selects an item the page disappears. I then work with the data that was selected.
How do I do this?
Thanks in advance
|
|
|
|
|
Try the ASP.NET[^] forum.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi.
Any of you have an working exampel of the function mmioInstallIOProcA??
|
|
|
|
|
Never mind..... made it work.
But thanks anyway.
|
|
|
|
|
I want to track the mouse position by drawing a line or cross at the location of the pointer.
What I can't figure out is how to erase the previous location from the display.
In other languages I would have done used a XOR pen but I can't find the same thing in C#.
I want the behavior to be something similar to the tracking line when panels are resized.
Thanks,
Eric
|
|
|
|
|
Hi, Im having trouble creating an rtp header at the moment as I need to convert a short into a 2 bytes for the sequence number!
I have tried going to an string them byte but this then produces 5 bytes not 2! and also using the Convert class but this only converts to a single byte!
How do I go about this?
Many thanks, Mat
|
|
|
|
|
Try BitConverter.GetBytes
|
|
|
|
|
Hi!
I am wondering about the c# code-technique "using".
As I understand, when the program leaves the using-block, the resourse defined whith the statement is disposed. In that case the two cases below should be identical:
//*** Case 1: (without myConnection.Close()) ***//
using(SqlConnection myConnection = new SqlConnection(sConnectionString))
{
SqlCommand myCommand = new SqlCommand("GetUsers", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myConnection.Open();
//Fetch data
}
//*** Case 2: (with myConnection.Close()) ***//
using(SqlConnection myConnection = new SqlConnection(sConnectionString))
{
SqlCommand myCommand = new SqlCommand("GetUsers", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myConnection.Open();
//Fetch data
myConnection.Close();
}
Can anyone confirm that there is no defferences between the who. Case 1 just seems a bit dangerous to me
Thanx!
/Paul
|
|
|
|
|
I think you are asking two questions:
1.
using (SqlConnection myConnection = new SqlConnection(sConnectionString))
{
}
is equal to
SqlConnection myConnection;
try {
myConnection = new SqlConnection(sConnectionString);
} finally {
if (myConnection != null)
myConnection.Dispose();
}
This works good and you can trust in it
2. The other question is if a Dispose call on a SqlConnection is going to close it and yes it does.
|
|
|
|
|
Hi
I want to write a program that use notifyicon but i don't want to use a form container . i create a console aplication and use a notifyicon !
everything was well but my icon does not responce events ?
my goal is to prevent showing a form and reduce memory usage .
how can reach this ?
Thanks Amir Jalaly
|
|
|
|
|
|
Hello,
I have a C# WMEncoder application which is using a C++ transform plugin(DirectShow), I would like to send additional information to the filter and recieve information from the filter.From the filter I can use the SendMessage() function, but how can I send information to the filter?
I tried to create another c++ com, where I give it the IUnknown of the filter(thru a property of the com I created) and use the QueryInterface() method(in a method called SetEvent() I created in the com) inorder to use the IMyInterface of the filter but I get an error trying to use it in C#:
"Object reference not set to an instance of an object"
|
|
|
|
|
While your explanation could use a little bit of elaboration, do make sure that you're accessing an instance of the COM object and not creating another one. This can be tricky in .NET. In your native application you could add an instance of your DMO to the RunningObjectTable (ROT; fairly easy in native code) and then get it out in your managed application using Marshal.GetActiveObject(string progId) (so make sure to register your COM object class with a ProgID).
Note that you can also send information to the filter using SendMessage , but you must P/Invoke it. The generic signature follows:
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd,
[MarshalAs(UnmanagedType.U4)] int msg,
IntPtr wParam,
IntPtr lParam); Depending on the message parameters and return code, you can redefine this a little differently. If you must pass a pointer to a struct, for example, you can do the following (since a pointer to a struct is the size of an IntPtr ):
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd,
[MarshalAs(UnmanagedType.U4)] int msg,
IntPtr wParam,
ref MyStruct lParam); What QueryInterface method are you using? Marshal.QueryInterface ? Please post some example code.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
About the sendmessage() explenation, I can use that function in my filter but I want the function to respond to data I send from the C# application to the filter, I dont know how to recieve that information in my C++ filter so I tried to write another native com which will be the mediator, where I send that com the pointer to the IUnknown of the filter that I retrieve in my encoder application using GetTransformPlugin function of the IWMEncTransform object, when I try using that I get the error:
"Object reference not set to an instance of an object".
I also tried a different way inorder to avoid using another com:
Trans is my IWMEncTransform object, and I use
IntPtr s1 = Marshal.GetIUnknownForObject(Trans.GetTransformPlugin());
To retrieve it's IUnknown interface.
Now I'd like to pass that IUnknown as an argument to Queryinterface function:
IntPtr ptr;
Marshal.QueryInterface(s1, ref guid, out ptr);
The question is what's my guid?
I tried to obtain my filter guid from its implementation code (C++), where it says:
// {bc4ed075-019c-4ba1-b69c-4ddd80e562a8}
DEFINE_GUID(IID_IMycamfilterapp,
0xbc4ed075, 0x19c, 0x4ba1, 0xb6, 0x9c, 0x4d, 0xdd, 0x80, 0xe5, 0x62, 0xa8);
Therefore I wrote:
System.Guid guid = new Guid(0xbc4ed075, 0x19c, 0x4ba1, 0xb6, 0x9c, 0x4d, 0xdd, 0x80, 0xe5, 0x62, 0xa8);
Marshal.QueryInterface(s1, ref guid, out ptr);
The code has no warnings/errors, but 'ptr' gets the value '0', which is obviously wrong.
Do you have any suggestion to get it work?
Do you think I should use a different approach in order to obtain my transform filter interface?
All I'm looking for is a simple way to send some information to my filter while it's running.
|
|
|
|
|
Hello everyone
I have written a little app to manage certificates.
Now getting the PRIVATE key from the certificate is, quick, simple and straight forward... but I just get a constant result for the Public Key...
here is an example (I have vut out most of the PVK, but you get the drift )
<result>
Public Key
<rsakeyvalue><modulus><exponent>AA==
Private Key
<rsakeyvalue><modulus>23aDb/XXXXXXXXXXXXXXXXXX+......=
Here is the code I have to get the Public key
<br />
using System;<br />
using CAPICOM;<br />
using System.Security.Cryptography;<br />
using System.Security.Cryptography.X509Certificates;<br />
using System.Runtime.InteropServices;<br />
using System.Windows.Forms;<br />
using System.Text;<br />
<br />
namespace CertificateManager<br />
{<br />
[StructLayout(LayoutKind.Sequential)]<br />
public struct PUBKEYBLOBHEADERS <br />
{<br />
public byte bType;
public byte bVersion;
public short reserved;
public uint aiKeyAlg;
public uint magic;
public uint bitlen;
public uint pubexp;
}<br />
<br />
public class PublicKey<br />
{ <br />
const uint CERT_SYSTEM_STORE_CURRENT_USER = 0x00010000;<br />
const uint CERT_STORE_READONLY_FLAG = 0x00008000;<br />
const uint CERT_STORE_OPEN_EXISTING_FLAG = 0x00004000;<br />
const uint CERT_FIND_SUBJECT_STR = 0x00080007;<br />
const uint X509_ASN_ENCODING = 0x00000001;<br />
const uint PKCS_7_ASN_ENCODING = 0x00010000;<br />
const uint RSA_CSP_PUBLICKEYBLOB = 19;<br />
const int AT_KEYEXCHANGE = 1;
const int AT_SIGNATURE = 2;<br />
static uint ENCODING_TYPE = PKCS_7_ASN_ENCODING | X509_ASN_ENCODING ;<br />
<br />
[DllImport("crypt32.dll")]<br />
public static extern bool CryptDecodeObject(<br />
uint CertEncodingType,<br />
uint lpszStructType,<br />
byte[] pbEncoded,<br />
uint cbEncoded,<br />
uint flags,<br />
[In, Out] byte[] pvStructInfo,<br />
ref uint cbStructInfo);<br />
<br />
<br />
private byte[] _modulus;<br />
private byte[] _exponent;<br />
<br />
public byte[] Modulus<br />
{<br />
get{return _modulus;}<br />
set{_modulus = value;}<br />
}<br />
<br />
public byte[] Exponent<br />
{<br />
get{return _exponent;}<br />
set{_exponent = value;}<br />
}<br />
<br />
public PublicKey(X509Certificate cert)<br />
{<br />
byte[] publickeyblob = null;<br />
byte[] encodedpubkey = cert.GetPublicKey();
<br />
uint blobbytes=0;<br />
<br />
if(CryptDecodeObject(ENCODING_TYPE, RSA_CSP_PUBLICKEYBLOB, encodedpubkey, (uint)encodedpubkey.Length, 0, null, ref blobbytes))<br />
{<br />
publickeyblob = new byte[blobbytes]; <br />
MessageBox.Show(Encoding.ASCII.GetString(publickeyblob));<br />
}<br />
<br />
<br />
PUBKEYBLOBHEADERS pkheaders = new PUBKEYBLOBHEADERS() ;<br />
int headerslength = Marshal.SizeOf(pkheaders);<br />
IntPtr buffer = Marshal.AllocHGlobal( headerslength);<br />
Marshal.Copy( publickeyblob, 0, buffer, headerslength );<br />
pkheaders = (PUBKEYBLOBHEADERS) Marshal.PtrToStructure( buffer, typeof(PUBKEYBLOBHEADERS) );<br />
Marshal.FreeHGlobal( buffer );<br />
<br />
<br />
<br />
byte[] exponent = BitConverter.GetBytes(pkheaders.pubexp);
Array.Reverse(exponent);
this.Exponent = exponent;<br />
<br />
<br />
int modulusbytes = (int)pkheaders.bitlen/8 ;<br />
byte[] modulus = new byte[modulusbytes];<br />
try<br />
{<br />
Array.Copy(publickeyblob, headerslength, modulus, 0, modulusbytes);<br />
Array.Reverse(modulus);
this.Modulus = modulus;<br />
<br />
}<br />
catch(Exception)<br />
{<br />
}<br />
}<br />
}<br />
}<br />
<br />
Can anyone tell me why I am getting such an odd result for the public key?
Hope someone can shed some light on this, as it's been driving me nuts!
Thanks in advance!
|
|
|
|
|