|
lukeer wrote: How can I serialize the collection including all objects derived from MyFantasticBaseClass?
By marking them all as Serializable , or implementing the ISerializable interface.
"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
|
|
|
|
|
Unfortunately, simply adding the [Serializable] attribute doesn't do the trick.
And as far as my tests show, the attribute isn't even necessary for serialization with System.Xml.Serialization.XmlSerializer.
The problem at hand is not serializing a class. That part works flawlessly, at least if _manyObjects contains nothing but instances of MyFantasticBaseClass.
Things get ugly when _manyObjects contains instances of children of MyFantasticBaseClass.
How can I get this to work?
Ciao,
luker
|
|
|
|
|
public class SecondDerivedClass : MyFantasticBaseClass
{
private double _zoom = 1.0;
private MyFantasticBaseClass _linkedElement = null;
public double Zoom
{
get { return (_zoom); }
set { _zoom = value; }
}
public MyFantasticBaseClass LinkedElement
{
get { return (_linkedElement); }
set { _linkedElement = value; }
}
}
This is a problem. the contained instance of MyFantasticBaseClassis initialized to null, and will throw the exception on serialization. Try initializing to a new MyFantasticBaseClass.
|
|
|
|
|
Hello To All,
I have found very diffrence between Text Printing and Text Using Image Printing
Case 1.
void PaintH(PaintEventArgs e)
{
System.Drawing.Bitmap bmp = new Bitmap(100,100);
Graphics G = Graphics.FromImage(bmp);
G.Clear(Color.White);
G.DrawString("Hello Everybody",this.font,this.col,this.rectangle1);
G.Dispose();
e.Graphics.DrawImage(bmp, 0, 0, bmp.width, bmp.height);
}
Case 2:
void PaintH(PaintEventArgs e)
{
G.DrawString("Hello Everybody",this.font,this.col,this.rectangle1);
}
Case 1 Printing quality is very bad. Case 2 Shows the real Printing Quality.
But I want to Print With the use of Case 1.
So Please Help.
Thanks
If you can think then I Can.
|
|
|
|
|
That happens because you use the default image resolution for your bitmap.
Add the next line right after the creation of your bitmap in order to set the proper resolution:
bmp.SetResolution(e.Graphics.DpiX, e.Graphics.DpiY);
|
|
|
|
|
but there is not same quality of both printing after applying this formula.
If you can think then I Can.
|
|
|
|
|
Yes, Nuri got it right. By default, a new bitmap takes the resolution of your primary monitor; printer resolutions may be quite different, which also means your bitmap may need quite a different size, hence 100,100 may not be enough depending on the printer you select!
|
|
|
|
|
Hi all,
I have some doubt, and it will be be help full if some one explain/elaborate on this. some variables which i am using. Whats my concern is where should i define them?
Approach 1, define with in function and modifying.
Class A
{
void CallingFunction()
{
string data = "";
DataTable dttemp = new DataTable();
bool isValid = false;
checkValue(ref data,ref isValid, ref dttemp);
}
private void checkValue(ref string msg, ref bool valid, ref DataTable dttemp)
{
msg += "Hello";
valid = false;
DataRow dr = dttemp.NewRow();
dr["cID"] = "2";
dttemp.Rows.Add(dr);
}
}
Approach 2, define at class level.
Class A
{
DataTable dttemp;
string data = "";
bool isValid = false;
void CallingFunction()
{
dttemp = new DataTable();
checkValue();
data = "";isValid = false; dttemp.Dispose();
}
private void checkValue()
{
data += "Some data";
isValid = true;
DataRow dr = dttemp.NewRow();
dr["cID"] = "2";
dttemp.Rows.Add(dr);
}
}
Whats the diffrence?
and when to use which?
|
|
|
|
|
First you have to ask youself if you have more than one DataTables.
In my oppinion you should use Approach 2 to solve you problem, Approach 1 is only wise if you have more than one instances of you objects and variables to check.
Well, i don't unterstand the intention of this code complete, maybe i can help more if you explain what are you planning to do
|
|
|
|
|
I am iterating in foreach loop, looking for some validation and then adding that to dttemp table;
foreach(Datatable dt in ds)
{
switch(dt.TableName)
{
case A:
foreach(DataRow dr in dt.Rows)
{
}
break;
.
.
.
case Z:
break;
}
}
Hope i make myself clear?
which is better way with reference to original post?
|
|
|
|
|
IMO, if you have just one datatable, the first approach is fine.
Why do you want to declare class level modules when you are using them only within a method.
My signature "sucks" today
|
|
|
|
|
Hum Dum wrote: Whats the diffrence?
Scope
Hum Dum wrote: and when to use which?
Use the second approach if the variables represent object-state, local variables and parameters if they don't. The hard part in that sentence would be defining "object state".
Let's take a Person class as an example. Now, if we introduce a variable for the age of the Person-object, then we're adding something that describes the state that the person is in. It contributes to the state of the object as a whole.
Next, if you want to iterate all arms that a person has, than you'd use a variable as a counter. That would be a local variable. If that variable were to be used to denote the amount of arms implemented, it would become a property.
I are Troll
|
|
|
|
|
Probably neither. But have separate classes (layers) to perform specific tasks -- perhaps the checkValue method should be in the Data Access Layer and the CallingFunction should be in the API layer.
checkValue should probably be defuined as bool checkValue(string msg, DataTable dttemp)
|
|
|
|
|
Here is an itemized list of reasons why:
1) Try to avoid using reference parameters. While they have a purpose they are difficult to maintain across developer experience levels and expectations.
2) Try to avoid using members as global variables. You introduce a lot of state into your objects that can be difficult to manage.
3) checkValue is misspelled. No matter which naming convention you use BE CONSISTENT! Your method should have been named CheckValue and yes it is an important distinction since checkValue tells experienced c# developers they are looking for a local variable.
4) CheckValue is a poor method name. Methods must be aptly named or chaos will ensue.
5) Your two samples actually have different results! See if you can find it.
6) Never use implicit scope.
7) I would provide a good example of how to do what you are asking, however, you code offers no clue as to the intent so the purpose of the question cannot even be inferred. However, I would suggest:
private DataRow CreateNewRow(DataTable table);
private bool IsDataRowValid(DataRow row);
private DataTable LoadDataTable();
private string CalculateSomeImportantDataFromRow(DataRow row);
Although, I personally would be using classes to represent my data instead of DataTables or Strongly typed data tables so my above suggestions do not take into account the "best" approach. Also, keep in mind, other than the CreateNewRow method no other method I described would have any side effects.
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: 2) Try to avoid using members as global variables. You introduce a lot of state into your objects that can be difficult to manage.
If by lot state to object you means when someone create a object of class A, then these object got attached by that. But they are private(default access specifier, if nothing mentioned). So how?
Ennis Ray Lynch, Jr. wrote: 3) checkValue is misspelled. No matter which naming convention you use BE CONSISTENT! Your method should have been named CheckValue and yes it is an important distinction since checkValue tells experienced c# developers they are looking for a local variable.
where it is misspelled? (may be, as typed it here not on VS)
I use camel casing, Why it named as CheckValue, if you explain( does you mean variable should start with small letter then Capital, and method will always be Caps. but i read it somewhere you use Capital Naming if that method is Public).
Ennis Ray Lynch, Jr. wrote: 5) Your two samples actually have different results! See if you can find it.
How tell me.
Ennis Ray Lynch, Jr. wrote: 6) Never use implicit scope.
By that you mean inside method or what?
Ennis Ray Lynch, Jr. wrote: I would provide a good example of how to do what you are asking
Let me explain?
I am picking an xml file from a folder, loading that in to DataSet object, iterarting its DataRow, doing some validation on XML nodes(Datarow), after validating them filling them in DataTable, applying sorting on this temp dataTable. and then genrating a text file.
|
|
|
|
|
Simplest code for your given problem: ( I just typed quickly and left stubs but it should give you an idea of a simple approach that is readable)
public static class Foo{
private static DataTable GetDataTableFromFile(string filePath);
private static bool IsRowValid(DataRow dataRow);
private static void WriteRowToStream(Stream stream);
public static void OutputXmlFileToTextFileOrSomeOtherJunk(string inputFilePath, string outputFilePath){
DataTable data = GetDataTableFromFile(inputFilePath)
using(FileStream stream = new FileStream(outpuFilePath, FileMode.Create, FileAccess.ReadWrite)){
foreach(DataRow row in data.Rows){
if(IsRowValid(row)){
WriteRowToStream(row);
}
}
}
}
}
|
|
|
|
|
hi friends
i have a c++ dll which contains function and class.
c++ dll code
class __declspec(dllexport) MyClass
{
public:
MyClass(void);
~MyClass(void);
void GetName()
{
.......
}
};
_declspec(dllexport) void MyFun()
{
}
My c# code follows
public partial class Form1 : Form
{
[DllImport("CPPDLL.dll", EntryPoint="MyFun")]
static extern void MyFun();
[DllImport("CPPDLL.dll", EntryPoint="MyClass")]
static class MyClass;
public Form1()
{
InitializeComponent();
}
}
but DllImport for class(MyClass) shows syntax error.
how can i solve this problem
thanks in advance
-kk.tvm-
|
|
|
|
|
DllImport doesn't work with classes. You can't import a class - if you need the class structure, it's up to you to redefine it as a struct at the C# side.
"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
|
|
|
|
|
Hi Pete O'Hanlon
Redefine ?
-kk.tvm-
|
|
|
|
|
It means you need to code up the C# equivalent.
"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
|
|
|
|
|
hi every one..
Is there any library or dll or any other tool for FREE to create or use skin for window forms.Please tell tool other than uskin,krypton toolkit.
and wpf concept.
thanks in adv..
|
|
|
|
|
There is a Component for skins, but it's a comercial product, but it's not expensive
The Name is "IrisSkin" from sunisoft, it's a really good component for use own skins.
Hope i could help you a bit.
|
|
|
|
|
But it is not for free. Is there any tool like that for free. I searchd on google but unable to find that.
|
|
|
|
|
I used to use IrisSkin, but the last time I tried, I ran into some problems. When using it in VS 2008, it turned out that the components flicker.
I notified Sunisoft, they said that they were able to reproduce the problem, but they never came back with a solution.
I haven't used the component since then, and I'm a little p'd off that they don't fix the problem seeing that I paid good money for the component.
|
|
|
|
|
I never had problem with flickering, i'm using it in VS 2008 too... the component works without any cause.
Did you check for updates? Maybe the developer have fixed the problem in a newer version of IrisSkin but haven't given feedback to you.
Which way the components flickers? Is it flickering everytime or only on certain Layout events?
|
|
|
|