|
|
Michael P Butler wrote: What is wrong with the above code?
Nothing!
But does it make sense to convert into its own type? or do we have need for it?
_____________________________
Success is not something to wait for, its something to work for.
|
|
|
|
|
Hi,
Iam new to c# ,is it possible to create a tool strip which can be moved to the middle of the form (similar to the toolstrips present in microsoft products),using vs2005.
thank you,
Regards
praveen
|
|
|
|
|
Hello,
I'm getting the following exception when I'm running my app:
SetCompatibleTextRenderingDefault must be called before the first IWin32Window object is created in the application.
I followed I tutorial to create a splash screen and my Program.cs file has been changed to:
static class Program
{
private static ApplicationContext context;
private static SplashForm sForm = new SplashForm();
private static MainForm mForm = new MainForm();
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
context = new ApplicationContext();
Application.Idle += new EventHandler(OnAppIdle);
sForm.Show();
Application.Run(context);
}
private static void OnAppIdle(object sender, EventArgs e)
{
if (context.MainForm == null)
{
Application.Idle -= new EventHandler(OnAppIdle);
mForm.PreLoad();
context.MainForm = mForm;
context.MainForm.Show();
sForm.Close();
sForm = null;
}
}
}
Everything is working fine, except when I uncomment this line:
Application.SetCompatibleTextRenderingDefault(false);
I get the exception mentioned above.
How can I solve that?
Thanks in advance.
|
|
|
|
|
The tutorial is wrong or you did not follow it correctly. Never had that probelem but from the code and the error message I would guess you can't have statically constructed forms if you want to call SetCompatibleTextRenderingDefault().
make sure you post the solution when you find it.
"Just about every question you've asked over the last 3-4 days has been "urgent". Perhaps a little planning would be helpful?" Colin Angus Mackay in the C# forum
led mike
|
|
|
|
|
This is the tutorial:
http://www.codeproject.com/csharp/apploadingarticle.asp
It was written for .NET 1.1 and I tried to convert it to version 2.0. I just didn't create a class named: AppLoader I used Program.cs instead.
Thanks.
|
|
|
|
|
Hi,
What is the difference between value types and structs in C#?
_____________________________
Success is not something to wait for, its something to work for.
|
|
|
|
|
a struct is a value type, but so is an int or a double.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
|
Thanks,
Thats more precise and clear.
Best Regards.
_____________________________
Success is not something to wait for, its something to work for.
|
|
|
|
|
With the minor exception that ValueType is an actual type that structs extend. Reference type is only a concept... Well not only, but there is no ReferenceType class. Or would object count? ehh, food for thought.
Try code model generation tools at BoneSoft.com.
|
|
|
|
|
BoneSoft wrote: With the minor exception that ValueType is an actual type that structs extend.
Got it, thanks.
And what i have little knowledge about a class is, its like a template for similar objects. Objects are called Reference types. Is that right?
Regards.
_____________________________
Success is not something to wait for, its something to work for.
|
|
|
|
|
All things .Net extend object, even ValueType. Ints and decimals and string, everything.
A class is the cookie cutter, objects are the cookies.
The primative types like int decmial and the like, plus anything that extends ValueType like enums and anything declared as a struct, are all value types. All interfaces and classes are reference types because they are always heaped. Balue types are meant to be simple because they are stacked.
Try code model generation tools at BoneSoft.com.
-- modified at 10:06 Thursday 29th June, 2006
Balue = Value
|
|
|
|
|
i am using a monthcalendar control in my form. and its my first time to use such control.
how would i be able to know what year is the current display of the calendar
after i clicked the buttons from either side of the navigation button?
one of the functionality of the form is also to save holidays on a certain date. and to determine that date to be a holiday, i should change the backcolor of the specific date of the calendar. how would i be able to do such?
thanks in advance.
|
|
|
|
|
Say I have a structue defined in c++:
struct Test
{
char first_name[80];
char last_name[80];
}
I then use an ostream to write an instance of that stucture to a binary file. How can I read that binary file in c#? I tried to create a similar structure in C# and then deserialize the binary file, but failed. I then read in my c# book that when you serialize an object, not only does the data get stored in the file but the object schema as well, so I can see why my code failed. So how do I go about reading the "pure" binary file in C#?
Thanks!
|
|
|
|
|
Just a shot in the dark, but when you read all the bytes in, are there 160 bytes? If so, that would mean there is no excess data stored, which would mean you could probably just read in the bytes, cast each byte to char, store the first 80 in firstName, the last 80 in lastName, then assign firstName and lastName to your struct fields.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Goof around music jam with my brothers (with video)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango Last modified: Tuesday, June 27, 2006 10:58:29 PM --
|
|
|
|
|
It must be something like this:
using(BinaryReader reader = new BinaryReader(new FileStream("myfile.bin", FileMode.Open)))
{
string firstname = Encoding.ASCII.GetString(reader.ReadBytes(80)).Replace("\0", "");
string lastname = Encoding.ASCII.GetString(reader.ReadBytes(80)).Replace("\0", "");
}
|
|
|
|
|
Can I use this structure in c#? I'm looking for a sample code for reading text file and throwing the values to textbox of richtextbox.
|
|
|
|
|
I dont think so. Just use the code above and put the firstname and lastname in textbox, using :
textBox.Text = firstname + " " + lastname;
|
|
|
|
|
I just wanna ask if what does 80 signifies in this code:
Encoding.ASCII.GetString(reader.ReadBytes(80)); -> the ReadByte(80)
is it the range to be read by the program?
|
|
|
|
|
Yes. reader.ReadBytes(80) return a byteArray with length 80.
Then Encoding.ASCII.GetString convert that byteArray to string.
|
|
|
|
|
So, this code:
using(BinaryReader reader = new BinaryReader(new FileStream("myfile.bin", FileMode.Open)))
{
string firstname = Encoding.ASCII.GetString(reader.ReadBytes(80));
string lastname = Encoding.ASCII.GetString(reader.ReadBytes(80));
}
returns the same value for firstname and lastname?
-- modified at 8:05 Wednesday 28th June, 2006
|
|
|
|
|
No. Firstname is the first 80 bytes. Lastname is the next 80 bytes.
|
|
|
|
|
The thing is, I simplified my question. In reality, the structure I am reading has a big list of vaiables of char arrays, and some ints and shortints. I was under the impression that I can somehow de-serialize it to eqiuvalent C# structure using some attributes or whatnot in System.Runtime.InteropServices. So I guess this is not the case?
|
|
|
|
|
Try to play with this code and see the file test.bin.
using System;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace ConsoleApplication22
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Test t;
t.firstname = "Hello".ToCharArray();
t.lastname = "World".ToCharArray();
using(FileStream fs = new FileStream("test.bin", FileMode.Create))
{
BinaryFormatter b = new BinaryFormatter();
b.Serialize(fs, t);
}
using(FileStream fs = new FileStream("test.bin", FileMode.Open))
{
BinaryFormatter b = new BinaryFormatter();
Test newt = (Test)b.Deserialize(fs);
}
}
}
[Serializable]
struct Test
{
public char[] firstname;
public char[] lastname;
}
}
|
|
|
|