|
Here[^]
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"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 all! It's my first time to write, hope somebody can help me
I am creating an application that at a certain point opens an all screen form formed by a "grid" of buttons.
I would like some of these buttons to visualize (besides a title) an image on them, that may be modified (e.g. become semi-transparent)at run-time: at the moment an event is fired (in particular clicking on the same button).
How should I do? Should I use the BackgroundImage or Image of the Button class? Should I put a PictureBox on the button? Or should I use to create my buttons another class than Button, maybe more complex and suitable for my purpose?
I already tried something, but with not much success!
Sorry for my English, thanx for your help!
Davide
|
|
|
|
|
Derive a class from Button, handle the paint event, and draw your image whatever way you like.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"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'm building an application that needs to sign some text. and than save the text and the signature in a file. Another application than reads this file and verifies it's contents using this hash. For this to work as I want, I need to convert the byte array containing the signature to a string to put at the end of the file. Next the recipient reads the string and converts it back to an byte array so the text can be verified.
I us the next code example to test. there are two blocks of code one using Encoding.Default and one using Encoding.Unicode. Using encoding.default works and give the correct answer true, the other does not.
Can anyone explain why using encoding.unicode doesn't work, or at least how to do the string <-> byte array conversions codepage independent?
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
using System.Security.Cryptography;<br />
<br />
namespace WindowsApplication1<br />
{<br />
public partial class Form1 : Form<br />
{<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
<br />
<br />
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();<br />
<br />
byte [] signature = RSA.SignData(Encoding.Unicode.GetBytes("test"), "SHA1");<br />
<br />
<br />
string temp = Encoding.Default.GetString(signature);<br />
signature = Encoding.Default.GetBytes(temp);<br />
<br />
bool verified = RSA.VerifyData(Encoding.Unicode.GetBytes("test"), "SHA1", signature);<br />
<br />
MessageBox.Show(verified.ToString());<br />
<br />
}<br />
}<br />
}<br />
|
|
|
|
|
The reason that you have problem decoding the signature to a string, is that it is not at all an encoded string to begin with.
When you are decoding it as if it were an encoded string, it depends on what encoding you are using and the content of the signature how much data you lose in the process.
If you want to send the signature as a string, just use Convert.ToBase64String and Convert.FromBase64String to get a string representation of the byte array and to get the byte array back.
---
single minded; short sighted; long gone;
|
|
|
|
|
I'm not going to pretend I completely understand your answer. I did however test using convert to and from base64 and it seems to work correctly and should be completely system independent as I understand it. I defenitely need to read up on my understanding of encodings.
Thanks for the quick answer!
|
|
|
|
|
I need help,
I had these sintax select id as random from table where id = '1', but this not help me.
If anybody can help me to write good sintax for select id random from a table
|
|
|
|
|
which database are you using?????
Signature has been encrypted
|
|
|
|
|
I am using MS SQL Server 2000
|
|
|
|
|
I asked this earlier, and Stefan Troschtz gave me an answer (thanks), but it wasn't what i was looking for and I think it was because i didn't explain it well enough. What code should i have in my program so that when a process is started of a file, and it is the type that my program opens, my program opens it? ex. when you start a process for a website, internet explorer opens it, when you open a .psd Photoshop opens it. Basically I am asking how i should pass the filename to my program so that it opens the file it should be opening. Or if that is not what you would do, what would you do?
Thanks again.
|
|
|
|
|
|
Firstly, it would have been better to keep this to the original thread where others could benifit from knowing what advice you've already been given.
Secondly, your application would need to process command line arguments.
As an example, if you had a text file named "myfile.foo" in the same directory as you appliation, you would be able to pass the filename to your application at the command prompt by typing "myApp.exe myfile.foo" or alternatively drag & drop the Foo file onto your exe.
This would start your application which could then perform any function you like.
It would obviously make sense that you application check the file extension ".foo" was correct before doing anything.
For more information on command line arguments, look here: http://msdn2.microsoft.com/en-us/library/acy3edy3.aspx
You could rig up a test application? If you create a new console application, you can paste the following code to replace the Main method:
public static void Main(string[] args)
{
if ( args.Length > 0 )
{
if ( args[0].ToLower().EndsWith(".foo") )
Console.WriteLine( "Openning Foofile named {0}", args[0] );
}
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
If you then build the application and create a text file named "test.foo" in the same folder, you should be able to drag & drop the Foo file onto your app.
This should run the app which simply displays the full path to the Foo file.
Once you've got this working, you've just got to create some method to actually do something with the file.
I guess it depends what you want it to do?
Lastly, you would have to associate an file extension with your application so that Windows knows what to do when somone tries to open this type of file. This is normally the job of an installer like InstallShield however, you can make this association manually.
If you double-click the Foo file, windows will normally complain that it cant open the file, then..
1) Simply select "Select a program from the list" and click "OK"
2) Tick the box which reads "Always use the selected program to open this kind of file"
3) The click the "browse" button where you can search for your application.
Foo files would always be opened by your application.
Hope this helps
Regards
Wayne Phipps
____________
Time is the greatest teacher... unfortunately, it kills all of its students
View my Blog
|
|
|
|
|
Hello, and thanks.
I can get the command prompt to work pretty well, but now I want a more graphical program. I have tried changing the code that you suggested and the code that I found at MSDN online to fit the Windows Interface template in Visual Studio 2005, but I have not been successful. I have tried searching some more for the solution, but have not found anything more about the Main(). So if you know of a website that would be helpful in creating what i am looking for, or if you have a quick simple solution, that would be very helpful.
Thanks again.
|
|
|
|
|
Ok, the pointer should have been enough to get the ball rolling. It showed one way to obtain the file name passed as a command line argument.
What you do from here on is up to you.
Windows Forms applications pass command line arguments in the same way, the only difference is how you reference the arguments.
One way would be to use a member variable to hold the filename. If you make this a public static you can then access if from anywhere within your application. You could do something as follows:
public static string FooFileName = null;
[STAThread]
public static void Main(string[] args)
{
if ( args.Length > 0 && args[0].ToLower().EndsWith(".foo") )
{
FooFileName = args[0];
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
public MainForm()
{
InitializeComponent();
if ( FooFileName != null )
{
MessageBox.Show( String.Format("FooFile Name: {0}", FooFileName) );
}
}
Another way would be to create a constructor which allows the filename to be passed as follows:
[STAThread]
public static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if ( args.Length > 0 && args[0].ToLower().EndsWith(".foo") )
{
Application.Run(new MainForm( args[0] ));
} else {
Application.Run(new MainForm( null ));
}
}
public MainForm( string FooFileName )
{
InitializeComponent();
if ( FooFileName != null ) MessageBox.Show( String.Format("FooFile name: {0}", FooFileName) );
}
Does that help??
If so maybe you would consider rating my answer? If not maybe we should consider further discussions via email.
Regards
Wayne Phipps
____________
Time is the greatest teacher... unfortunately, it kills all of its students
View my Blog
|
|
|
|
|
|
Take a look at the Interop classes provided by Microsoft for interacting with Word and Excel etc. Although these will require that Word is installed on the same machine. Alternatively there are some controls available on the internet (both free and commercial) that will do spell checking for you.
|
|
|
|
|
Hi,
I am using Panasonic KX-TEM824 PABX board. I want read data using C#.NET.
I used Serial Port package in C#.NET 2.0. But its not receiving any data.
Please give me a soloution.
THnx in advance
Thnx
Naffi
|
|
|
|
|
Hi Naffi,
I have a few questions:
1). Which operating system are you using with your PBX?
2). Are you using the Programmator software with your hardware?
3). Which version of Visual Studio are you using? I assume you are using VS 2005+ for the serial port support.
4). Are you receiving any data at all at the port?
Try connecting the hardware to your computer and use hyperterminal to determine if you are receiving data to the port.
Ron Birkelbach
Kennebec, Inc.
|
|
|
|
|
need help
how do I insert values into textbox exists in word-xp document using c# .net framework 1.1 (vs2003)
I don't want to use the VSTO
thank you,
|
|
|
|
|
You could possibly get the handle of the window through WinAPI and then send the text to the window using WinAPI, I believe the command that you would use is SendMessage.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
Hi to all, i'm a Biogenetic student and i don't know anything about programming.
Now, i'm looking for someone that can help me to implement some simple phylogenetic algorithms that construct phylogenetic relationship among biological sequences.
There are some kinds of algorithms, such as the follow: Clustering Algorithms, Cladistic methods. I haven't limitation in programming about one algorithm in particular.
What i found is a simple program that draw, in a Windows Form, the output of one o this methods.
Please help me.
|
|
|
|
|
Huh Ehm ... try to clearify a bit ... I'm lost
|
|
|
|
|
I am trying to create a class which other classes can use for passing info to the main form, called: class InfoDisplay:
<code>
class InfoDisplay
{
public delegate void ehMainInfoShow(string s);
public event ehMainInfoShow evtMainInfoShow;
public InfoDisplay()
{
// do nothing
}
public void ShowMainInfo(string s)
{
evtMainInfoShow(s);
}
}
</code>
In my main form's constructor, I have the following (for linking the delegate to the function I think?):
<code>
...
private InfoDisplay m_infoDisp;
public MainForm() // Constructor
{
InitializeComponent();
InfoDisplay m_infoDisp = new InfoDisplay();
m_infoDisp.evtMainInfoShow += new InfoDisplay.ehMainInfoShow(ShowMainInfo);
}
private void btnTest_Click(object sender, EventArgs e)
{
m_infoDisp.ShowMainInfo("Updating file info");
}
private void ShowMainInfo(string s) // Linked to InfoDisplay class for passing data back to Mainform
{
txtBoxInfo.AppendText(s + "\n"); //this puts an annoying square at the end of the line ( ? )
}
</code>
When I click the button which calls the method btnTest_Click, it works fine (outputs the string "Updating file info", to the text box).
However, when another class (all in the same namespace), DataFetcher, below, attempts to create a new InfoDisplay object and call the method ShowMainInfo(), an error results:
<code>
class DataFetcher
{
private InfoDisplay m_infoDisp;
public DataFetcher()
{
m_infoDisp = new InfoDisplay();
}
public void GetData(string fileName)
{
m_infoDisp.ShowMainInfo("Loading file...");
...
// Error occurs on the above line (when the method is called from another class that has created an instance of this one):
// "Object reference not set to an instance of an object."
</code>
If anyone has any help with this problem I'd really appreciate it... Is there a delegate declaration missing somewhere - or perhaps its not possible
to have this arrangement of a general 'proxy' class for passing info to the main form via events..?
Many thanks for any help!
Gerry
C# newbie
Put A Smile On Your Face
http://www.thecrazywebsite.com
|
|
|
|
|
The problem is that no event handlers are registered to the evtMainInfoShow event when you call ShowMainInfo in the DataFetcher class. Why? Simply because in the DataFetcher you're cteating a new instance of the InfoDisplay class that does not now you registered an event handler to the instance created in the main form. To overcome the problem of the exception being thrown when you call ShowMainInfo you have to check whether there are any event handlers registered to your event before calling it. Its common practise to encapsulate this in a protected OnEvent method:
class InfoDisplay
{
public delegate void ehMainInfoShow(string s);
public event ehMainInfoShow evtMainInfoShow;
public InfoDisplay()
{
}
public void ShowMainInfo(string s)
{
evtMainInfoShow(s);
}
protected void OnMainInfoShow(string s)
{
if (evtMainInfoShow != null)
evtMainInfoShow(s);
}
}
Besides that change I suggest you also create a special EventArgs class that carries the string message and name this class and the delegate so they conform to the common naming pattern (eventHandler and eventArgs).
To overcome the problem of creating multiple instance of the InfoDisplay class, I'd suggest you let the class implement the singleton pattern so there exists only one instance that is accessible throughout your application. Let the main form register to the event of this instance and all other classes call ShowMainInfo.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Phew!
Thanks a million Stefan, I think I see what you mean (ie. what the problem is).
OK I'm gonna try and get my head around this singleton pattern
(If you have any links to a good source of info on how to do this, that'd be awesome!)
Mit freundlichen grussen (I used to live in Frankfurt, I miss Germany! Nice site you got btw, impressive Vitae! )
Gerry
|
|
|
|