|
Try list.Cast<IIndexedListItem>()
|
|
|
|
|
If you don't want to use all that fancy LINQ stuff, you can use List.ConvertAll to convert from a list of one type to a list of another type:
List<Animal> myAnimals = (new List<Dog> { new Dog() }).ConvertAll<Animal>(delegate(Dog d) { return d; });
|
|
|
|
|
Hello all
I want to write an application for a Windows CE or Pocket PC device that will print to a printer. I.e. My application will be on a handheld device and i will connect my handheld device to the printer by USB cable, when the user clicks print it will print the printer that the user has set up on that handheld device. wondering if someone could point me in the right direction for information on how to do this. I just want to print text in different fonts. Is this possible in C#?
Thank you
|
|
|
|
|
I have never tried it, don't know if it works, etc., but you might look Smart Device Print Engine for Compact Framework[^]
I don't know how well it will all work - you may need to talk to the physical printer in it's own langauge as I've never seen a printer driver specifically for Windows CE/Mobile.
Let us know if it works, I'd be very interested...
[edit]Don't post the same question in multiple places: It duplicates work and annoys people. If I had known you had posted in here and in Q&A then I would probably have replied there. I have deleted your Q&A question.[/edit]
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Hi All,
I am new in this .and i have to create a application in which a virtual Directory in IIS and aal the details from sql server will be fatched and shoing in our application.anybody can guide me how i can create it.....I'll wait for reply...
regards:
Gourav
+91-9871157845
|
|
|
|
|
Here it is.[^]
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.aktualiteti.com
|
|
|
|
|
In my application I have a picturebox control which displays a bitmap I have created from a byte array. This works quite well most of the time, however if I resize the form the image will sometimes get corrupt. Sometimes it even draws other bitmaps that are being used by completely different forms.
This[^] is what the picturebox looks like when it's doing what it's supposed to.
Random corruption[^] Note that this isn't actually random at all. Whenever I get a pattern similar to this, it's the exact same pattern.
More corruption[^]
I haven't overridden the paint event for the picturebox or anything fancy like that. The only owner-drawn control in the form is the rainbow colour bar you can see on the right.
I've googled this to death and haven't been able to come up with anything, I'm really lost here. Help is well-appreciated.
|
|
|
|
|
How did you create the bitmap from the byte array?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
private Bitmap createBitmap(uint width, uint height, byte[] pixels)
{
if (width == 0)
{
throw new ArgumentException("Bitmap width must be greater than 0.");
}
if (height == 0)
{
throw new ArgumentException("Bitmap height must be greater than 0.");
}
UInt32 byteCount = width * height * 4;
System.IntPtr pPixels = System.Runtime.InteropServices.Marshal.AllocHGlobal((int)(byteCount));
System.Runtime.InteropServices.Marshal.Copy(pixels, 0, pPixels, pixels.Length);
Bitmap bmp = new Bitmap((int)width, (int)height, (int)width * 4, System.Drawing.Imaging.PixelFormat.Format32bppArgb, pPixels);
System.Runtime.InteropServices.Marshal.FreeHGlobal(pPixels);
return bmp;
}
|
|
|
|
|
Hi,
the corruption you are seeing is typical when there is a mismatc in the image width, i.e. when scanlines are wider/narrower than the metadata indicates.
There are many ways to create a bitmap; any way that creates them from raw data requires the data to remain available as long as the image lives (i.e. isn't garbage collected), e.g.:
1. Image.FromFile() locks the file, as it may need to read the file again;
2. Image.FromStream() reqeusts the stream remains available and intact (although it often doesn't matter);
3. new Bitmap(..., rawDataPointer,...) requires the raw data to be available permanently.
1. enforces the file presence by locking the file (of course you could still get disconnected from the drive); 2 and 3 can't enforce anything, and are the likely cause for your image corruption.
BTW: all the above is in the fine manual, so RTFM.
|
|
|
|
|
Thanks for the info, that will be very helpful..
I guess C# has spoiled me... it has much better intellisense support than C++ - as a result I haven't found myself needing to read any of the documentation on msdn
|
|
|
|
|
You're welcome.
Whatever intellistuff they add, as long as MSDN holds more, one should read it. The remarks section is quite valuable most of the time.
|
|
|
|
|
Hi i am new in c#.
I am developing an application which have a main form(frmstart) and second form (frmreader).
i am moving from frmstart to frmReader form by a button click.
it work fine.
before moving to frmReader i hide frmStart. now i am on frmReader and i want to return back to my previous frmStart form. which is hidden. please tell me how to unhide the form.
# code MovetoFrmReader
frmReader R1 = new frmReader();
this.Hide();
R1.Show();
#code Returmback to frmStart
this.Dispose();
???
here in place of ??? what i need to write.
Please Help me.
Thanks
Ravindra
|
|
|
|
|
Firstly, don't use Dispose, use Close instead - it will be disposed later when the CG gets round to it. Remember that your form may have results that the main form expects to be able to pick up.
Instead, either
1) Pass the frmStart instance to frmReader (not brilliant, but it will work) and use the Show method on it before you Close() frmReader. This may give you problems if you miss a way to close teh form that you are not handling.
or
2) Use R1.ShowDialog(); instead of R1.Show(); This will prevent frmStart from proceeding until frmReader is closed. It can then unhide itself. (Much preferable, as frmReader can be more generic and does not need to know about the existance of frmStart)
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
OriginalGriff wrote: it will be disposed later when the CG gets round to it.
Nah. I don't expect Christian flies around the world collecting our junk.
|
|
|
|
|
Good spot!
|
|
|
|
|
Luc Pattyn wrote: I don't expect Christian flies around the world collecting our junk.
He can't - all airlines suck today
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Handle the FormClosing event of R1 in frmstart and it can unhide itself.
using System;
using System.Windows.Forms;
public partial class FormStart : Form
{
public FormStart()
{
InitializeComponent();
Click += new EventHandler(FormStart_Click);
}
private void FormStart_Click(object sender, EventArgs e)
{
ShowFormReader();
}
private void ShowFormReader()
{
FormReader formReader = new FormReader();
formReader.FormClosing += new FormClosingEventHandler(formReader_FormClosing);
formReader.Show();
Hide();
}
private void formReader_FormClosing(object sender, FormClosingEventArgs e)
{
Show();
}
}
If it's not a close of R1 that triggers this then you can easily create a custom event and handle that.
|
|
|
|
|
WRT your code, I want to get data from FormReader to FormStart.
I uses following 2 approaches:
A)
FormReader formReader = new FormReader(this);
Now, making FormStart member as internal/public accessing them on FormReader.
B)On click(here its closing) event handler as you did
private void formReader_FormClosing(object sender, FormClosingEventArgs e)
{
}
But here i have to make FormReader Member internal/public
My question is,
Which approach is good?
As in first we are making parent form member public,
But,In 2nd we are child form member public.
Or is there any other way?
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Also If i have a case like
interface IA
{
void M();
}
interface IB
{
void M();
}
class ABC : IA, IB
{
public void M()
{
MessageBox.Show("Hello");
}
}
ABC a = new ABC();
a.M();
Whose Interface method i am implementing?
Its running not giving error?
What is the use of this definition ?
And what should i do if i want to implement IA not IB or vice versa.
Or by default its calling/implementing IA M, as it's mentioned 1st as ABC:IA,IB
|
|
|
|
|
With regard to your first question - getting data from FormReader to FormStart :
Do NOT use method A. It works but it is a nasty hack that as things get more complex you will regret!
Method B does not require any change to the access modifier of FormReader . The sender parameter will (normally) be the FormReader instance. So, inside the handler add something like this:
FormReader formReader = sender as FormReader;
if(formReader != null)
{
}
There is another method if you want FormReader to inform FormStart that there is data it may be interested in - you can raise a custom event in FormReader and subscribe to that in FormStart . Have a look at this tip[^], this tip[^], then this article[^] if this would fit your case better.
|
|
|
|
|
Sorry, forgot your second question!
The answer is neither. An interface has no implementation so you never actually use any methods/properties/events they appear to have. You always use the implementation in the class that provides the implementation.
|
|
|
|
|
Dave's approach is fine.
Maybe a simpler approach is also acceptable: if the one form is hidden while the other is shown, the latter probably could be shown as a dialog, hence:
this.Hide();
otherForm.ShowDialog();
this.Show();
|
|
|
|
|
I finally made it working!!! I made a test here actually and i made it work. I can save and load from a text file...yeeey.
How can I made it more compact? I want to transform it into a stand alone Class that I can call it from anywhere in any situation. Any suggestions?
Thanks
Here is the code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SaveLoadNamespace;
using WarningsNamespace;
using System.Text.RegularExpressions;
namespace test7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SaveLoadClass slc = new SaveLoadClass();
WarningsClass wc = new WarningsClass();
string tampon;
private void buttonSave_Click(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
tampon = "checkBox = true" + "\r\n";
}
else
{
tampon = "checkBox = false" + "\r\n";
}
tampon += "numericUpDown = " + numericUpDown1.Value.ToString() + "\r\n"; ;
tampon += "comboBox = " + comboBox1.Text + "\r\n"; ;
slc.file_SaveFile(tampon); label2.Text = wc.w2;
}
string buffer, s = ""; int i, j = 0;
private void buttonLoad_Click(object sender, EventArgs e)
{
slc.file_LoadFile(); label1.Text = buffer = slc.textToLoadInto; label3.Text = wc.w5;
#region <_____ NumericUpDown _____>
if (buffer.Contains("numericUpDown"))
{
i = buffer.IndexOf("numericUpDown");
s = buffer.Remove(0, i);
if (s.Contains("\r\n"))
{
i = s.IndexOf("\r\n");
j = s.Length - i;
s = s.Remove(i, j);
}
if (s.Contains("="))
{
i = s.IndexOf("=") + 1;
s = s.Remove(0, i).Trim();
}
i = int.Parse(s);
numericUpDown1.Value = i;
}
#endregion >NumericUpDown-END<
#region <_____ checkBox _____>
if (buffer.Contains("checkBox"))
{
i = buffer.IndexOf("checkBox");
s = buffer.Remove(0, i);
if (s.Contains("\r\n"))
{
i = s.IndexOf("\r\n");
j = s.Length - i;
s = s.Remove(i, j);
}
if (s.Contains("="))
{
i = s.IndexOf("=") + 1;
s = s.Remove(0, i).Trim();
}
if (s.Contains("true"))
{
checkBox1.Checked = true;
}
if (s.Contains("false"))
{
checkBox1.Checked = false;
}
}
#endregion >checkBox-END<
#region <_____ comboBox _____>
if (buffer.Contains("comboBox"))
{
i = buffer.IndexOf("comboBox");
s = buffer.Remove(0, i);
if (s.Contains("\r\n"))
{
i = s.IndexOf("\r\n");
j = s.Length - i;
s = s.Remove(i, j);
}
if (s.Contains("="))
{
i = s.IndexOf("=") + 1;
s = s.Remove(0, i).Trim();
}
comboBox1.Text = s;
}
#endregion >comboBox-END<
}
}
}
The output is like this:
checkBox = true
numericUpDown = 24
comboBox = red
|
|
|
|
|
Hi,
you could build a method to which you can pass a form. To get the controls at the passed form use the Controls-Property:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controls.aspx[^]
Check the type of each control to get the name like 'checkBox' for your string.
Btw: Instead of using the type-name of each control I would suggest using the ID, so that you can store more than one checkbox for example.
Hope this helps you a bit.
Regards
Sebastian
|
|
|
|
|
Its a good suggestion and i understand it because i see it some time ago used by others ... But, its too advanced for me for the moment and I wish to make it in some limited way that i can understand what i write there... But,I will look into it and I will strive to understand it how its done and try to use it...but small chance for me to accomplish that kind of maneuverability.
Thanks
|
|
|
|