|
hi
how can i convert a decimal value to its ASCII equivalent in C#?
thanks
|
|
|
|
|
Probably char c = 65 would do it.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
try this code:
<br />
private string ConvertToAscii(decimal value)<br />
{<br />
Encoding ascii = Encoding.UTF32;<br />
<br />
char chr = (char)value;<br />
Byte[] bty = ascii.GetBytes(chr .ToString());<br />
<br />
return ascii.GetString((bty));<br />
}<br />
|
|
|
|
|
Why on earth does it take a decimal ?
This looks like a convoluted mess to me. I just did this and traced in the debugger:
int n = (int)'C';
char c = (char)n;
it worked just fine.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
My question is "How to send a user defined variable value while calling eventhandler.
Pls go thru the below example:
1. I have an array of Pictureboxes arranged on a Panel
2. I have handled the Click event on PictureBoxes as below but dont know:
how to pass "string FilePath" as part of "Object sender"
<br />
<br />
string FilePath;
picBoxes[index].Click += new System.EventHandler(ClickHandler);<br />
<br />
...<br />
...<br />
<br />
public void ClickHandler(Object sender, System.EventArgs e)<br />
{<br />
<br />
PictureBox pbx = new PictureBox();<br />
pbx = (PictureBox) ((System.Windows.Forms.PictureBox)sender);<br />
<br />
<br />
}<br />
<br />
Thanks
|
|
|
|
|
Hello,
I think what you want to do is only possible with an Inherited class and the usage of Custom Eventargs.
1) Inherit a class from PictureBox
public class SpecialPictureBox : System.Windows.Forms.PictureBox
2) Add a string property FilePath
private string _filepath = "";
[System.ComponentModel.DefaultValue("")]
public string FilePath
{
get
{
return _filepath;
}
set
{
_filepath = value;
}
}
3)Inherit a class from System.EventArgs with a string member
public class SpecialEventArgs : System.EventArgs
{
public string filepath;
public SpecialEventArgs(string _filepath)
{
filepath= _filepath;
}
}
4)Create a delegate for your special event in your SpecialPictureBox class, which uses the SpecialEventArgs.
public delegate void SpecialEvent(object sender, SpecialEventArgs specialEA);
5)Create an event which uses the delegate
public event SpecialEvent SpecialChanged;
6)override the OnClick event of your PictureBox and fire the event, with the Filepath property.
if(SpecialChanged!=null)
{
SpecialChanged(this, new SpecialEventArgs(this.FilePath));
}
7)In your Form Handle the SpecialChanged event and set the FilePath property
yourSpecialPictureBox.FilePath = "yourpath";
yourSpecialPictureBox.SpecialChanged+= new YourNamespace.SpecialEvent(yourSpecialPictureBox_SpecialChanged);
private void yourSpecialPictureBox_SpecialChanged(object sender, SpecialEventArgs specialEA)
{
}
Hope it helps!
-- modified at 5:35 Friday 27th July, 2007
All the best,
Martin
|
|
|
|
|
Oh wow, didnt think about it! let me try. Thank you Martin.
|
|
|
|
|
You are wellcome!
Hope it works out for you.
Please let us know.
All the best,
Martin
|
|
|
|
|
In .NET Framework 2.0, if you're following the EventArgs pattern, you don't need to declare your own delegate, you can use the generic EventHandler<T> delegate. Saves time and metadata space.
So you'd have
public event EventHandler<SpecialEventArgs> SpecialChanged;
yourSpecialPictureBox.SpecialChanged +=
new EventHandler<SpecialEventArgs>(yourSpecialPictureBox_SpecialChanged); I'm finding this pretty handy.
|
|
|
|
|
Hello Mike,
Mike Dimmick wrote: In .NET Framework 2.0,
I'm one of the poor, who have to work with .Net1.1 only.
But thanks for the info!
All the best,
Martin
|
|
|
|
|
Yes, This solution works properly! though a bit advanced for me!
thanks
|
|
|
|
|
Glad I could help!
Thanks for the feedback!
All the best,
Martin
|
|
|
|
|
Hi,
I want include the some Matlab lib files in my C# progrm than what is a procedure to link the matlab with C#.Net?
|
|
|
|
|
There isn't one, unless matlab comes in dlls you can p/invoke
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
There is no direct way to use the Matlab files in C# however, using the Matlab Builder for .Net you can convert Matlab functions to .Net methods. Write all the required function in m-code (encapsulate) and build using .Net Builder which will generate a .Net Assembly file which can be used in your C# program.
You will need Matlab version R2006a (with MATLAB Builder for .NET).
Also checkout the website http://www.mathworks.com/access/helpdesk/help/toolbox/dotnetbuilder/[^]
Hope this works!
~Sky
|
|
|
|
|
Hi,I have a problem. I have a DirectX application written in C++ and i want to embed it in a C# Windows form. Is that possible and how?
|
|
|
|
|
Not really, no, you can't embedd one app in another in a supportable way.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I use the following code (obvious not my coding) in my program:
public static bool CovertToGray(Bitmap bmp)<br />
{<br />
<br />
BitmapData bmData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),<br />
ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);<br />
int stride = bmData.Stride;<br />
System.IntPtr Scan0 = bmData.Scan0;<br />
unsafe<br />
{<br />
byte* p = (byte*)(void*)Scan0;<br />
byte red, green, blue;<br />
int nOffset = stride - bmp.Width * 3;<br />
for (int y = 0; y < bmp.Height; ++y)<br />
{<br />
for (int x = 0; x < bmp.Width; ++x)<br />
{<br />
blue = p[0];<br />
green = p[1];<br />
red = p[2];<br />
p[0] = p[1] = p[2] = (byte)(.299 * red<br />
+ .587 * green + .114 * blue);<br />
p += 3;<br />
}<br />
p += nOffset;<br />
}<br />
}<br />
bmp.UnlockBits(bmData);<br />
return true;<br />
}
Questions are
What is the function of BitmapData?
Why PixelFormat.Format24bppRgb is used?
What is this int stride = bmData.Stride;?
Why unsafe used?
In short I can’t understand the 50% of above code for convert the picture in grayscale format?
I want learn……..please guide me …..I am waiting for your response
|
|
|
|
|
1 - it contains the bits of the image
2 - probably because 32 bits is a waste of time and < 24 is hard to process
3 - each image in memory has an area at the end of each scanline which does not contain pixels and should not be accessed.
4 - because you can't use pointers in C# outside an unsafe block
This looks like it came from my image processing article, didn't I explain all of this there ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
minimilist question
minimilist answer [^]
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
|
|
|
|
|
With the ToArray() method
Seriously, your question makes no sense, what is in the struct, that it makes sense to turn it into an array ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi...
I am newbie in c#, please help me on clr trigger.
I have done a clr trigger and everytime i debug my c# code,an error occured on this part
AIClass.AICheck.checkUserRole();
The error description is like this :->
InvalidOperationException was Unhandled
The requested operation requires a SqlClr context, which is only available when running in the Sql Server process.
I dont know what to do...
And I cannot create a trigger inside Sql Server Express Edition 2005. I did like this:->
create trigger tgAI
on AIEvent
for insert
as
external name
AIAssembly.AIClass.userRoleCheck
and the error appeared:-> Msg 6505, Level 16, State 1, Procedure tgAI, Line 1
Could not find Type 'AIClass' in assembly 'AIClass'.
my code in c# is like this (will be called in the main class in console App.):->
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Server;
using System.Data;
using System.Data.SqlClient;
namespace AIClass
{
public class AICheck
{
//[SqlTrigger(Event = "FOR INSERT", Name = "AI_tg", Target = "AIEvent")]
public static void checkUserRole()
{
SqlTriggerContext tgContext = SqlContext.TriggerContext;
//SqlConnection conn = new SqlConnection("Data Source=DIMENSION3000\\SQLEXPRESS; Initial Catalog=AITania; User Id=sa; Password=123456");
using (SqlConnection conn = new SqlConnection("context connection=true"))
conn.Open();
SqlCommand cmd = conn.CreateCommand();
SqlDataReader reader;
string msg = "";
if (tgContext.TriggerAction == TriggerAction.Insert)
{
//SqlCommand sqlComm = new SqlCommand();
//SqlPipe sqlPipe = SqlContext.Pipe;
cmd.CommandText = "SELECT * FROM INSERTED";
reader = cmd.ExecuteReader();
//sqlComm.Connection = conn;
//sqlComm.CommandText = "SELECT * FROM INSERTED";
//for (int x = 0; x < tgContext.ColumnCount; ++x)
//{
// msg += string.Format("Column {0} {1} been updated{2}", x, (tgContext.IsUpdatedColumn(x) ? "has" : "has not"), Environment.NewLine);
//}
for (int i = 0; i < reader.FieldCount;i++ )
{
msg = msg + reader.GetName(i) + ":" + (string)reader[i] + " ";
}
}conn.Close();
}
}
}
Please help me..
thanks..
-jack-
|
|
|
|
|
You cant use that code outside the SQL environment, you will have to specify a proper SQL connection string.
|
|
|
|
|
hi leppie..
hem..thanks for the suggestion...but still blur..
so..how do i supposed set the connection string properly..
whenever i debug my project..it came out like this...
The Error:
AIClass.AICheck.checkUserRole();
--> invalidOperationException was unhandled
--> The requested operation requires a SqlClr context, which is only available when running in the Sql Server process.
i have search at msdn help online but still cannot find the answer..
please help me...
thanks a lot
Jac
|
|
|
|