|
Hi,
In my application i have to print receipt using Dot Matrix Printer(EPSION LQ-300+II). My receipt have preprinted format, in this format i have to send datas using C# code.
My papers size is:Height:10 Inch and Width 9.5 inch. The paper is regular paper.
The problem is in first page datas are printed in required location but in next page it is printed in other location. So, How to set paper size in Crystal Report using C# application for this case: I have set like this:
Reports.frmCrViewer.PaperSize = PaperSize.Paper10x14;
Reports.frmCrViewer.PaperOrientiation = PaperOrientation.DefaultPaperOrientation;
this syntax is correct but the paper size Paper10*14 didn't matched my requirement. So, what should i have to do to print in paper having size 10*9.5 inch.
Please Help Me
|
|
|
|
|
I have a StreamWriter used to create log files and it works fine the first time but if I try to use it again writes fail because the file is not open to write to.
This is called to create a new log file:
FileStream fs = new FileStream(timestr, FileMode.CreateNew);
ScriptData.LogFile = new StreamWriter(fs);
ScriptData.LogFile.WriteLine("Logile created {0:yyyy'-'MM'-'dd'T'HHmmss}.log", DateTime.Now);
This is called to close a file:
ScriptData.LogFile.WriteLine("Script {0} completed.", ScriptData.LogName);
ScriptData.LogFile.Close();
ScriptData.LogFile.Dispose();
ScriptData persists outside the scope of these calls.
Any ideas? All I want to do is be able to write ASCII text to log files.
Thanks.
|
|
|
|
|
Where and how do you destroy the filestream object fs?
The problem is, if you close the underlying filestram, you also close the file.
Greetings
Covean
|
|
|
|
|
The StreamWriter is a member of Scriptdata which is persistent.
|
|
|
|
|
Take a look at your code!
<pre>FileStream fs = new FileStream(timestr, FileMode.CreateNew);
ScriptData.LogFile = new StreamWriter(fs);</pre>
Now if you close fs then your StreamWriter can be a static item from hell, its closed cause you closed the underlying filestream!
StreamWriter is just a class to have a simpler way to transfer data from and to a file.
The FileStream itself "represents" the file!
Greetings
Covean
|
|
|
|
|
Elaine - rather than rolling your own logging solution, you should really look into using something like log4net[^]. We use it all the time now.
"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
|
|
|
|
|
Pete,
that looks good but I'm not sure it would do what I need which is basically to capture the input from a serial port, write it to a file and occasionally insert comments along the way.
Log4net seems to be about logging for the application whereas I am logging the embedded target being controlled.
|
|
|
|
|
That wouldn't be a problem. Instead of calling your log code, you can call Log.Write on the log4net log manager. You might want to log to the messagequeue and log from there, for instance.
"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 all,
i want to create an application(c#) through which i need to send and receive sms using gsm modem or phone.so i need some basic idea regarding this. please help
|
|
|
|
|
This would be the best place to learn about basics of SMS.
Developers home[^]
you can create your own framework, after reading the basics...
All the best...
Have a Happy Coding.....
|
|
|
|
|
You can use at commands for interacting with modem.
|
|
|
|
|
Hi,
This very long post consists of a relatively short question and a lot of background information. Please read at least the question before deciding this isn't worth your time!
Question
Does anyone know if it's feasible to inject code into a precompiled object at runtime? I suppose it would be quite tricky, but I am not sure since the .NET Framework has surprised me many times by providing easy ways to do previously difficult things!
What I want is to have a bunch of objects implement an interface by generating this implementation at run-time. Existing instances (at the time of generating the implementation) of the type would have to be replaced by the generated type, and still be "seen" as the same type (I don't know much about how type checking is implemented in the runtime) by all the other precompiled code.
Is this possible? If so, and if anyone knows how to do it, or more likely where I can find the information I need to figure out how to do it, I'd very much appreciate the help.
Background
If anyone thinks what I am trying to do seems very odd and find themselves thinking there must be better ways to achieve the same, here's that background. The following doesn't really add to my question, although it's possible of course that there is some other way of achieving the result I desire, so I think it's worth including it.
I'm toying around with making a fairly general data access framework intended for rapid prototyping purposes. The emphasis is therefore on minimal programming and configuration (for the user of the framework), and sensible default behaviors that would work in most if not all situations but need not be optimal in terms of performance or scalability. However, I find myself thinking if I can achieve this and also get good performance, that would be pretty awesome and make the framework into something far more valuable than just a prototyping tool.
I want to completely encapsulate the storage system so it's essentially reduced to exposing just two operations: Load and Save. (Some other types would also be exposed, such as attributes to override default behaviors, a Selection type to specify a subset of objects to load at once, interfaces the entity objects may implement to optimize performance by letting the storage system ask the object if it has changed since it was loaded, and more. But only two operations: Load and Save.) When saving and loading objects I want to do so based on fields, not properties, since the fields always contain the true state of the object. The user of the framework would therefore not need to necessarily expose everything as properties that are read-write, and that's important to me, since using read-only properties is a very good way to encapsulate and protect state in many cases.
I know this can be achieved by using reflection to read and write the fields. However, I find myself thinking that if I could somehow inject change the type that is being loaded or saved at run-time so it implements a simple interface, I could instead use reflection to generate code that relies on the interface to get and set private fields of the object. This would lead to considerable overhead the first time a type is saved or loaded, but then be very fast since the generated and compiled code would simply be reused.
Here is some very very incomplete code to illustrate the idea:
public class Toto
{
int n;
string s;
Toto parent;
}
public class Storage
{
static public ObjectManagerFactory ObjectManagerFactory { get; set; }
Dictionary<Type, IObjectManager> objectManagers;
public List<T> Load<T>(Selection selection)
{
IObjectManager m;
Type t = typeof(T);
if (!objectManagers.TryGetValue(t, out m))
{
m = ObjectManagerFactory.CreateManager(t);
objectManagers[t] = m;
}
return (T)m.Load(selection);
}
public void Save(object data) { ... }
}
Now imagine my user wants to save an instance of Toto. He would have to first have instantiated the Storage class (but this is obviously intended to have the same lifetime as the application, since otherwise caching the object managers would not have as much effect), but then the code would just be something like this:
Storage.Save(toto);
What I would like to do, but doubt is actually possible, is to modify the Toto type so it becomes something like this:
public class Toto : IFieldAccessible
{
int n;
string s;
Toto parent;
object[] IFieldAccessible GetFieldValues()
{
return new object[] { n, s, parent };
}
void IFieldAccessible SetFieldValues(object[] values)
{
n = (int)values[0];
s = (string)values[1];
parent = (Toto)values[2];
}
}
Since the code that would use the two interface methods is also dynamically generated there should be no problem with having to rely on the index in the object arrays to know what field belongs to what value.
The trouble is I don't know if this is even possible (I doubt it!) and much less how it could be done if it is. Also, I don't think it can be done by hooking into the build process, because the types that may be loaded or saved aren't necessarily known at compile-time.
|
|
|
|
|
No, you can't; yes, a workable solution could be found, probably with Reflection.
If you are talking about encapsulating a database, how will you specify the details of that?
dojohansen wrote: I want to do so based on fields, not properties, since the fields always contain the true state of the object
That would needlessly limit which types you could use.
You also need to understand more about generics -- you don't need the objectManagers Dictionary.
|
|
|
|
|
Thanks for trying. Unfortunately I disagree with what little you had to contribute.
Basing it on fields doesn't in any way constrain what types can be used. Fields *are* the entire state of any object. Properties often reflect state, but far from always, and they need not be writeable and indeed often should not be.
As for reflection, that would be easy, but not performant. The point of my post was I already know how to do this with reflection, but I want to avoid it and do something fast instead.
I'm now wondering if I can use dynamc methods built using reflection.emit. Then I would not need to modify any existing type, merely to generate a type which accesses the private fields of another type. It must be possible some way or another, since FieldInfo.GetValue can do it...! Don't know what IL to emit though.
Perhaps if I cache the fieldinfo instances performance won't suffer too much and reflection alone will do..?
|
|
|
|
|
Maybe you want to consider using a variation of the ideas presented in this[^] article.
"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
|
|
|
|
|
dojohansen wrote: need not be writeable
Fields may not be writable either (or even readable), and indeed often should not be. My point is that if you support both fields and properties, you support a greater number of types.
dojohansen wrote: As for reflection, that would be easy, but not performant
If it's the only way, then it's the fastest way.
dojohansen wrote: cache the fieldinfo instances
That's what I would do.
|
|
|
|
|
Fields being nothing more than a portion of memory corresponding to a part of a type value, it is *always* writeable. A constant (literal) isn't writeable, but a field ultimately is. At least I believe readonly fields is nothing more than a compile-time check, and not some run-time check of whether the code attempting to access a field is allowed to do so.
|
|
|
|
|
dojohansen wrote: it is *always* writeable
Nope.
And are you planning to write to private fields? I don't recommend that.
dojohansen wrote: At least I believe readonly fields is nothing more than a compile-time check
Try it.
P.S. I just tried it and it worked!
modified on Wednesday, November 4, 2009 9:47 PM
|
|
|
|
|
Hi experts........
how to use towords() function in crystal reports......
Thanks in advance
|
|
|
|
|
Can anyone suggest me how to change the colour of scrollbar of richtextbox/panel/gridview ?
As we change the Windows theme, the colour of scroll bar changes.
I want to depict this behaviour in one of my application, but without changing the windows theme.
Thanks in advance!
|
|
|
|
|
Hi,
I only had a look at DataGridView but suppose it is similar for the other controls. The grid does not expose the scrollbar objects, it only exposes the ScrollBars property which is just an enum to define if you want no scrollbars, horizontal/vertical only, or both.
Hence, there is no API for doing what you want to. You can access the scrollbar via the Controls collection, but be aware that if the implementation details of the DataGridView changes, your code may break.
The absolutely easiest and worst way is to simply index into this collection. I tried this code:
void foo()
{
var g = new DataGridView();
ToString();
}
The second line is just a dummy for me to set a breakpoint so I could have a look in the watch list. Set a breakpoint there, make sure something calls foo(), and run. Then add the watch g.Controls and you'll see that by default the grid contains two controls, the horizontal and the vertical scrollbar. Hence, this code would succeed for such a grid:
g.Controls[0].BackColor = Color.Red;
However, the scrollbar may of course not be the first control of the datagrid in all situations, such as when we've databound it. A more robust solution would be to search a part of the control tree for a given type and use that to find the scrollbar. Then your code would depend only on the grid or whatever control contains it having one and only one sub-control of type HScrollBar (for the horizonal one).
Let's put this general code in a separate class so it can be reused, and call it Util for now (you may want to bundle this method with related functionality and make it into a ControlUtil or WinFormsUtil or whatever).
static public class Util
{
static public T Find<T>(Control container) where T : Control
{
foreach (Control child in container.Controls)
return (child is T ? (T)child : Find<T>(child));
return null;
}
}
Now you can use this to find and access subcontrols not directly exposed by the container. You may also want to add a FindAll method to find all subcontrols of a particular type, or one that searches by using a predicate function so you can select a subcontrol based on it's property values rather than only on type. But you get the idea, hopefully.
Usage: Util.Find<HScrollBar>(dataGridView1).BackColor = Color.Red;
Remember however that this approach is not guaranteed to work if and when you move to a new framework version. The grid does not expose any HScrollBar and is free to replace this with some other implementation in the future, in which case your code would break.
Also, for the Panel or other container controls, this won't be enough if the control contain any other controls that have scrollbars! Find here simply returns the first subcontrol found of the given type, and it searches depth first (i.e. if the first subcontrol is not the given type, search it's subcontrols before continuing to the next sibling). But you can adapt this to search level by level if you want, or restrict it to searching only the direct children of the container (I don't know if a Panel's scrollbars are direct children, but it's likely) or use any other method of your choosing to find the appropriate object. In any case you can use the central idea of gaining access to the subcontrol by finding it in the control subtree - as long as you accept that this logic may not be valid forever and might have to change if the controls do.
|
|
|
|
|
Hi there
How do you bind (in WindowsForms) with a textbox to a datasource property with the type of 'decimal?' (that is, Nullable<decimal>)?
To do a straightforward binding is simple, I got that to work, i.e. when you type a value in the textbox it updates in the datasource properly but when I empty out the textbox, I expect the property to have a value of null but the textbox refuses to loose focus or to have any other event to take place until a valid number is entered.
Did anyone had a similar issue?
Let me know if its not clear enough.
Thanks
- Last Attacker
|
|
|
|
|
i want to control mouse movement and clicking using my own application how can i achieve this
|
|
|
|
|
You can achieve it via windows api by sending messages to controls.
|
|
|
|
|
Thanx
if i need some more help regarding the project how can i contact you
|
|
|
|
|