|
I used this to start learning about MEF it shows a good couple of exercise on how to use MEF etc.
http://channel9.msdn.com/Events/TechEd/NorthAmerica/2010/DEV304[^]
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
Is this you[^]?
I don't mean to sound paranoid, but there's a possibility that you couble be re-posting StackOverflow questions[^] here so you can copy the answer and get the points.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I am the same guy, i posted it here because i didnt get an answer there.
|
|
|
|
|
I have a custom control called EditorSection which contains a Button control for the header and a RichTextBox control. I have another custom control called EditorContainer which can contain multiple EditorSection controls. In the EditorContainer I have a Button control for "Print All", which obviously should print all of the EditorSection controls' content.
I created a class called "PrintSection", which stores the title (header text) for each section as well as a string array for the "Lines" property of the RichTextBox in each EditorSection custom control. All is fine so far.
When I click "Print All" I would like to print each section's header title and then prints that section's content below it, which will sometimes span more than one page. This is where I have a problem. I'm not sure how to achieve multi-page printing with this setup.
Here is how I populate a List<printsection> object:
this._printSections = new List<PrintSection>();
foreach (Control child in sectionsPanel.Controls)
{
if (child is EditorSection)
{
PrintSection section = new PrintSection();
section.Name = ((EditorSection)child).SectionName;
section.Lines = ((EditorSection)child).GetLines();
this._printSections.Add(section);
}
}
The "GetLines()" method returns the "Lines" property for the RichTextBox in the EditorSection control, while "SectionName" is the section's header title.
Here is what I have tried so far with printing:
int sectionIndex = 0, lineIndex = 0;
void document_PrintPage(object sender, PrintPageEventArgs e)
{
Graphics g = e.Graphics;
Font font = new Font(SystemFonts.DefaultFont.FontFamily.Name, 9.5f);
Font headerFont = new System.Drawing.Font(font.FontFamily.Name, 12.0f, FontStyle.Bold);
float yPos = 0;
PrintSection section = this._printSections.ElementAt(sectionIndex);
{
g.DrawString(section.Name, headerFont, Brushes.SteelBlue, 0, yPos);
yPos += (g.MeasureString(section.Name, headerFont).Height + 4f);
g.DrawLine(Pens.LightSlateGray, 0, yPos, g.MeasureString(section.Name, headerFont).Width * 2, yPos);
yPos += (g.MeasureString(section.Name, headerFont).Height);
for (int l = lineIndex; l < section.Lines.Count(); l++)
{
string line = section.Lines[l];
g.DrawString(line, font, Brushes.Black, 0, yPos);
yPos += (g.MeasureString(line, font).Height);
lineIndex++;
}
yPos += 32f;
if (sectionIndex < (this._printSections.Count - 1))
{
sectionIndex++;
e.HasMorePages = true;
}
}
}
The "sectionIndex" variable holds the zero-based index of the section currently being printed. I am able to print each section on its own page, which is desirable. However, I would eventually like to allow for printing continuously without making a new page for each section, as an option to the user.
The problem I am facing is this. How do I print the section's lines on more than one page if it doesn't fit on one page? I have the "yPos" variable which is the current position on the y-axis for printing. I have tried "if (yPos > pageHeight) { e.HasMorePages = true; }" but it doesn't print the remaining lines on a new page.
What am I doing wrong?
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
One call to the PrintPage handler is responsible for printing a single page. So if you want to be able to split sections between pages, you need to save some state information which allows the second call to the method to pick up a section part way through (just as you're currently storing sectionIndex so the next run of the method knows where to start).
|
|
|
|
|
Right. I just didn't know what I was doing wrong because I tried something like that. However, I *did* figure it out. I had to add a "break;" statement:
for (int l = lineIndex; l < section.Lines.Count(); l++)
{
string line = section.Lines[l];
g.DrawString(line, font, Brushes.Black, 0, yPos);
yPos += (g.MeasureString(line, font).Height);
lineIndex++;
if (yPos > e.PageBounds.Height)
{
e.HasMorePages = true;
break;
}
}
Because without the "break;" it was continuing the "for" loop until all lines had been processed. The "break;" causes it to go to the end of the PrintPage handler with "HasMorePages" set to true, which would pick up where it left off. I'm not sure how I skipped over that to begin with but your response seemed to set off a light bulb in my head. Thanks!
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
Hi I'm writing a client/server remote viewer (desktop sharing) application where screenshots of the desktop are sent across the network over a socket. I'd like to reduce the size of the transfer by getting the difference between the two images and then sending the difference. on the other hand difference will be merge with previous image at other end.
so anyone please guide me how could i accomplish this job. still now i send every time a complete image of the screen over the network programatically and program at other end just show that image. i feel huge data is getting pass over the network and screen update rate at the other end is slow. so please show me good way how to compare between two images and send only difference to other end. also tell me how to merge the difference with actual image at other end.
1) lots of free code and library is available for image comparison but i just do not understand which one i should use and which one would very faster for comparison. so just guide me regarding this.
2) and the most important part is how to send difference only over the network and merge the difference with actual image at other end
i tried lot to get some info regarding my point 2 but got nothing similar. no article i found who can guide me that how to send difference only over the network and merge the difference with actual image at other end
so i am looking for in-depth discussion for my point 2 specially. thanks
tbhattacharjee
|
|
|
|
|
Why re-invent the wheel what you can use a library that does all this for you, such as VNCSharp[^]
|
|
|
|
|
This is one of those questions where you're asking us to do everything for you – and a copy and paste job from another forum judging by the formatting.
You need to (i) make a reversible diff (i.e. something which fully encodes the differences), (ii) send it, and (iii) apply it at the other end. The libraries that you say you've found for (i) should also do (iii), and (ii) is trivial. You need to actually try and then you can come back with specific problems.
|
|
|
|
|
|
My application is C# .net Framework 3.5.
The main functionality of the application is:
let the user choose a network interface card (NIC)
assign to the user selected NIC an IP address (and subnet mask) - I use WMI - EnableStatic method of Win32_NetworkAdapterConfiguration class.
start through a Process a 3rd party C++ exe component, behaving like a server, which will be listening to the given IP address - the binding functionality is implemented by the server, so on Process start up I just give pass the proper IP address and it starts listening on that one.
Operation 2 and 3 can be repeated an unlimited number of times, thus it's possible to assign to the very same NIC several IP addresses and have multiple servers, each one listening to the its own IP address.
To assign the IP address to the given NIC I use WMI, in particular this code, where adapterGUID is the GUID of the user selected NIC and newSettings it's a class holding a list of IPs and subnet masks:
public static bool ChangeNetworkInterfaceIPs(string adapterGUID, IpSettings newSettings)
{
try
{
if (String.IsNullOrEmpty(adapterGUID))
throw new ArgumentException("adapterGUID");
ManagementBaseObject inPar = null;
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
ManagementObject moTarget = null;
foreach (ManagementObject mo in moc)
{
if ((string) mo["SettingID"] == adapterGUID)
{
moTarget = mo;
break;
}
}
if (moTarget == null)
{
mc = null;
return false;
}
object winsSecondary = moTarget.GetPropertyValue("WINSSecondaryServer");
object gateways = moTarget.GetPropertyValue("DefaultIPGateway");
object dnsDomain = moTarget.GetPropertyValue("DNSDomain");
object dnsServers = moTarget.GetPropertyValue("DNSServerSearchOrder");
object winsPrimary = moTarget.GetPropertyValue("WINSPrimaryServer");
if (newSettings.DHCP)
{
inPar = moTarget.GetMethodParameters("EnableDHCP");
moTarget.InvokeMethod("EnableDHCP", inPar, null);
}
else
{
inPar = moTarget.GetMethodParameters("EnableStatic");
inPar["IPAddress"] = newSettings.Ips;
inPar["SubnetMask"] = newSettings.Netmasks;
moTarget.InvokeMethod("EnableStatic", inPar, null);
}
if (gateways != null && !newSettings.DHCP)
{
inPar = moTarget.GetMethodParameters("SetGateways");
inPar["DefaultIPGateway"] = gateways;
outPar = moTarget.InvokeMethod("SetGateways", inPar, null);
}
if (dnsDomain != null && !newSettings.DHCP)
{
inPar = moTarget.GetMethodParameters("SetDNSDomain");
inPar["DNSDomain"] = dnsDomain;
outPar = moTarget.InvokeMethod("SetDNSDomain", inPar, null);
}
if (dnsServers != null && !newSettings.DHCP)
{
inPar = moTarget.GetMethodParameters("SetDNSServerSearchOrder");
inPar["DNSServerSearchOrder"] = dnsServers;
outPar = moTarget.InvokeMethod("SetDNSServerSearchOrder", inPar, null);
}
if (winsPrimary != null && !newSettings.DHCP)
{
inPar = moTarget.GetMethodParameters("SetWINSServer");
inPar["WINSPrimaryServer"] = winsPrimary;
if (winsSecondary != null)
{
inPar["WINSSecondaryServer"] = winsSecondary;
}
outPar = moTarget.InvokeMethod("SetWINSServer", inPar, null);
}
return true;
}
catch
{
return false;
}
}
Now, my problem comes when the user wants to kill one the active servers. On server closure I have to remove from the NIC the IP address the server was listening to.
Killing the process it's not a problem, but when I call my ChangeNetworkInterfaceIPs to update the IP assigned to NIC (removing the one of the server no longer in use) using a new list of IP address (namely: the old list without the ip address of the killed server) something very strange happens: randomly some of other running servers get a SOCKET_ERROR and their connection it's closed.
Any idea on what's happening? Why the running servers are randomly getting SOCKET_ERRORs when I remove an unused IP address from the NIC ? Additionally, I know that probably setting a whole list of IP addresses just to remove one it's not really a best practice: is there a way to remove just a given IP address?
I hope the question is clear enough. Thank you for your time.
|
|
|
|
|
The problem occurs probably because the underlying code in the Win32_NetworkAdapterConfiguration class deletes all the IP's from the adapter and rewrites the list of IPs, or at least partially so.
Using WMI, there's nothing you can do about it. Also, the 3rd party server apparently isn't tolerant of the IP binding changing or disappearing for a brief time. There's nothing you can do about that either, except find another product.
One method I've used to get around screwy problems like this is to run this stuff in virtual machines, one server instance = one VM. If you need to change the IP or the server, mearly shutdown the VM, make any IP changes to it, reatart the VM and the server comes up not knowing anything happened.
|
|
|
|
|
thank you for you support Dave.
I came exactly to the same conclusion as well.
Sadly due several reason we cannot use VMs, so I'm still struggling in order to find a proper solution / work around.
Cheers
|
|
|
|
|
Hi all,
I want to create an application which detects the webcam to take the photos and this application should work on any platform,operating System.
Please can any one suggest me how can i start creating this application.
Thanks in advance
|
|
|
|
|
sarang_k wrote: I want to create an application which detects the webcam to take the photos and this application should work on any platform,operating System.
Good luck with that. So, you want it to work on Android, or Linux, or iOS, or Mountain Lion, or Windows. You aren't going to get the same codebase to do all that.
|
|
|
|
|
i think we can write the code by using different conditions,like when u open a browser and a site it detects the things from site automatically what player or plugins r required.
|
|
|
|
|
You really can't.Taking the browser example, the browser itself is compiled differently for different platforms.
|
|
|
|
|
ok
Atleast can u tell me how can i implement in windows OS ?
|
|
|
|
|
Hello Everyone
Can someone please tell me if there is a equivalent to java's ResourceBundle class in C#?
kind regards
lapeci
|
|
|
|
|
Sort of. Basically, you create resource files that are locale specific or default locale, and .NET takes care of a lot of the heavy lifting for you. Have a read of this[^] article to get you started.
|
|
|
|
|
While debugging, I am seeing the following error messages from the code at the bottom. Do I need some sort of time out period for my this.invoke commands?
Thanks for reading!
DisconnectedContext was detected
Message: Context 0x3eb6e0' is disconnected. Releasing the interfaces from the current context (context 0x3eb570).This may cause corruption or data loss. To avoid this problem, please ensure that all contexts/apartments stay alive until the applicationis completely done with the RuntimeCallableWrappers that represent COM components that liveinside them.
ContextSwitchDeadlock was detected
Message: The CLR has been unable to transition from COM context 0x3eb570 to COM context 0x3eb6e0 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.
<pre>this.Invoke((MethodInvoker)delegate()
{
string uptime = GetUptime(server.TrimEnd()).ToString();
string days = "";
int firstPeriodIndex = uptime.IndexOf('.');
int firstColonIndex = uptime.IndexOf(':');
int daysIndex = 0;
if (firstPeriodIndex < firstColonIndex)
{
daysIndex = uptime.IndexOf('.');
if (daysIndex >= 0)
{
days = uptime.Remove(daysIndex);
}
}
else
{
days = "0";
}
string hours = uptime.Remove(0, daysIndex + 1);
int hoursIndex = hours.IndexOf(':');
if (hoursIndex >= 0)
{
hours = hours.Remove(hoursIndex);
}
string minutes = uptime.Remove(0, daysIndex + 1);
minutes = minutes.Remove(0, hoursIndex + 1);
int minutesIndex = minutes.IndexOf(':');
if (minutesIndex >= 0)
{
minutes = minutes.Remove(minutesIndex);
}
string seconds = uptime.Remove(0, daysIndex + 1);
seconds = seconds.Remove(0, hoursIndex + 1);
seconds = seconds.Remove(0, minutesIndex + 1);
int secondsIndex = seconds.IndexOf('.');
if (secondsIndex >= 0)
{
seconds = seconds.Remove(secondsIndex);
}
if (_shouldStop == true) { return; }
lvwShutdown.BeginUpdate();
if (lvwShutdown.Items[selectedIndex].SubItems[2].Text != "")
{
lvwShutdown.Items[selectedIndex].SubItems[2].Text = "";
}
lvwShutdown.Items[selectedIndex].SubItems[3].Text = days + " D, " + hours + " H, " + minutes + " M, " + seconds + " S";
lvwShutdown.EndUpdate();
lvwShutdown.Refresh();
});
|
|
|
|
|
I am putting together a WCF example using queues.
So far the client pops a message on the service queue, and the service in turn pops an acknowledgement on the client queue.
There are two technical pieces still challenging me.
Each client nominates and creates its queue at run time. I am struggling to get at the endpoint in the client tags on the service side app.config to use the address passed up by the client for the response - not so much to edit the as to build an alternative programaticaly at run time.
The other was on the client side when the response comes back. I open a host using a client side contract in the client form. The neatest way to trigger an event in the form was inspired by this post: Events from Service
Ger
modified 3-Dec-12 18:14pm.
|
|
|
|
|
Hi.I want to add image to picturebox in swith case building.Could you help me?.I'm study on Windows Form.
|
|
|
|
|
Try:
Image myImage = null;
switch(imagenumber)
{
case 0: myImage = Image.FromFile(@"D:\Temp\CatPic.jpg"); break;
case 1: myImage = Image.FromFile(@"D:\Temp\DogPic.jpg"); break;
case 2: myImage = Image.FromFile(@"D:\Temp\LlamaPic.jpg"); break;
}
myPictureBox.Image = myImage; But it's bad practice to use magic numbers and fixed file names...
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
When I used to execute my code, I used to be able to step into the following line of code in my PC class, and it went to my GetProgramControl method, where I could step some more.
controls[i] = (Control)_type.InvokeMember("GetProgramControl", BindingFlags.Default | BindingFlags.InvokeMethod, null, _objectInstance, _parameters);
For some reason, I was stepping into that at one point, and it was having trouble finding my SN.cs and I hit the link to browse to show it where it was. Ever since then, every time I step into the line above, it goes directly to the later reference of my SN class and the debugger is in a method there. Any ideas how I can get the debugger to stop in the PC class GetProgramControl method? I can't put a breakpoint there because it's outside of my class that is calling it.
I looked at the following but it's different since my SN class isn't a child of PC, it's a reference used in it.
http://bytes.com/topic/c-sharp/answers/439984-cant-step-into[^]
I also saw this and it might be similar but it doesn't look like anyone had a solution for him: http://www.codeproject.com/Messages/2932838/Can-t-step-into-method-debug-with-F11-in-Visual-St.aspx[^]
|
|
|
|
|