|
Another Idea.
Leave the hi-res images as hi-res so the customer can open them and see the difference. But put distinct watermark, so when printed it does not look good.
|
|
|
|
|
Hi all,
I am trying to have my program detect when the system's memory is low. Is there an event or a windows API that I can use to achieve this?
Thanks in advance.
|
|
|
|
|
What for?
No, I don't think you can do that in a reliable way, short of actually requesting lots of memory until you aren't getting any more.
Each new version of Windows is trying harder to have all memory in use all the time, by caching everything they encounter.
|
|
|
|
|
I just need to find a way that will let me know if the OS's memory/resources is low. Is there a windows API or maybe an event in .Net that I can just plug-in to?
|
|
|
|
|
I haven't had it happen since I got more than 512MB ram, and set a decent size page file, however I recall windows pops a message for you if you are running out of memory. It would ask permission to increase the size of the page file. Leave it to Windows I say.
|
|
|
|
|
It's called try/catch . That's the best you can do. Besides, what *is* low memory in windows? It pages to disk, so you shouldn't have to worry about it.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
|
Yes, you can observe the GC.GetTotalMemory, query the WMI information or use the unmanaged APIs. But as you've been told above, this does not make much sense in general... Your question makes sense, if your application itself manages chunks of memory for specific purposes, such as caching.
P.S. The situation is different, if we are talking about some kind of mobile device...
modified on Sunday, August 29, 2010 6:54 AM
|
|
|
|
|
It's generally pointless to try.
|
|
|
|
|
I am trying to access a property on a System.__ComObject by name. I can do this for normal objects:
var mapping = m.GoogleMapping as SimpleGoogleMapping;
var propInfo = googleContact.GetType().GetProperty(mapping.PropertyName);
googleValue = propInfo.GetValue(googleContact, null);
googleContact is a normal class so this doesn't cause a problem.
I tried this (outlookContact is a ContactItem retreived using Outlook Interop, but during debugging, shows as a System.__ComObject):
var mapping = m.OutlookMapping as SimpleOutlookMapping;
var propInfo = outlookContact.GetType().GetProperty(mapping.PropertyName);
propInfo.SetValue(outlookContact, googleValue, null);
But propInfo ends up being null , even though the property name is correct. I've also tried:
var propInfo = typeof(ContactItem).GetProperty(mapping.PropertyName);
without success.
Edit: Using outlookContact.GetType().GetProperties() or typeof(ContactItem).GetProperties() returns an empty list, as does GetMembers() .
Does anyone know how to achieve this with a dynamic object?
I am using .Net 4
|
|
|
|
|
You cannot query a COM wrapper for CLR properties since it does not have any. Have you tried to extract the properties directly from the assembly which defines the COM CoClass? Something like this:
using System.Reflection;
const string sOutlookInteropAssemblyName =
"Microsoft.Office.Interop.Outlook";
const string sContactItemTypeName =
"_ContactItem";
PropertyInfo FindProperty(string pPropertyName) {
Assemby tOulookInterop =
Assembly.ReflectionOnlyLoad(sOutlookInteropAssembly);
Type tContactItemType =
tOutlookInterop.GetType(sContactItemTypeName);
PropertyInfo [] tProperties =
tContactItemType.GetProperties();
return tProperties.Find(Property => Property.Name == pPropertyName);
}
Huch, there is a lot of stuff which can go wrong, I just typed in the code without checking it, but I hope you get the point.
modified on Saturday, August 28, 2010 4:28 AM
|
|
|
|
|
Can anyone help me this is my whole code
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
using System.Runtime.InteropServices;<br />
using System.Diagnostics;<br />
using Gadgets.Properties;<br />
<br />
namespace Gadgets<br />
{<br />
<br />
public partial class Form1 : Form<br />
{<br />
<br />
public const int WM_NCLBUTTONDOWN = 0xA1;<br />
public const int HTCAPTION = 0x2;<br />
[DllImportAttribute("user32.dll")]<br />
public static extern bool ReleaseCapture();<br />
[DllImportAttribute("user32.dll")]<br />
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);<br />
<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
pictureBox2.MouseDown += new MouseEventHandler(p2_MouseDown);<br />
<br />
}<br />
Note newNote = new Note();<br />
Search newSearch = new Search();<br />
SRLS newSRLS = new SRLS();<br />
Alarm newAlarm = new Alarm();<br />
QuickLaunch newQuickLaunch = new QuickLaunch();<br />
Calender newCalender = new Calender();<br />
Time newformtime = new Time();<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
notifyIcon1.Visible = true;<br />
<br />
if (timeToolStripMenuItem.Checked == true)<br />
{<br />
newformtime.Visible = true;<br />
}<br />
if (alarmToolStripMenuItem.Checked == true)<br />
{<br />
newAlarm.Visible = true;<br />
}<br />
if (calenderToolStripMenuItem.Checked == true)<br />
{<br />
newCalender.Visible = true;<br />
}<br />
if (sRLSToolStripMenuItem.Checked == true)<br />
{<br />
newSRLS.Visible = true;<br />
}<br />
if (searchToolStripMenuItem.Checked == true)<br />
{<br />
newSearch.Visible = true;<br />
}<br />
if (noteToolStripMenuItem.Checked == true)<br />
{<br />
newNote.Visible = true;<br />
}<br />
if (quickLaunchToolStripMenuItem.Checked == true)<br />
{<br />
newQuickLaunch.Visible = true;<br />
}<br />
<br />
<br />
timeToolStripMenuItem.Checked = Settings.Default.timecheck;<br />
alarmToolStripMenuItem.Checked = Settings.Default.calendercheck;<br />
calenderToolStripMenuItem.Checked = Settings.Default.alarmcheck;<br />
sRLSToolStripMenuItem.Checked = Settings.Default.srlscheck;<br />
searchToolStripMenuItem.Checked = Settings.Default.searchcheck;<br />
noteToolStripMenuItem.Checked = Settings.Default.notecheck;<br />
quickLaunchToolStripMenuItem.Checked = Settings.Default.quickLaunchcheck;<br />
<br />
}<br />
<br />
private void p2_MouseDown(object sender, MouseEventArgs e)<br />
{<br />
if (e.Button == MouseButtons.Left)<br />
{<br />
ReleaseCapture();<br />
SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);<br />
}<br />
}<br />
<br />
private void p1_MouseMove(object sender, MouseEventArgs e)<br />
{<br />
this.pictureBox1.Image = Properties.Resources.minimize2;<br />
}<br />
<br />
private void p1_MouseDown(object sender, MouseEventArgs e)<br />
{<br />
this.pictureBox1.Image = Properties.Resources.minimize3;<br />
}<br />
<br />
private void p1_MouseLeave(object sender, EventArgs e)<br />
{<br />
this.pictureBox1.Image = Properties.Resources.minimize1;<br />
}<br />
<br />
<br />
<br />
<br />
<br />
private void pictureBox1_Click(object sender, EventArgs e)<br />
{<br />
this.Visible = false;<br />
}<br />
<br />
<br />
<br />
<br />
<br />
private void copyright_MouseMove(object sender, MouseEventArgs e)<br />
{<br />
this.copyright.Image = Properties.Resources.l2;<br />
}<br />
<br />
private void copyright_MouseLeave(object sender, EventArgs e)<br />
{<br />
this.copyright.Image = Properties.Resources.l1;<br />
}<br />
<br />
private void copyright_MouseDown(object sender, MouseEventArgs e)<br />
{<br />
this.copyright.Image = Properties.Resources.l3;<br />
}<br />
<br />
private void copyright_Click(object sender, EventArgs e)<br />
{<br />
System.Diagnostics.Process.Start("www.systemerror.co.nr");<br />
}<br />
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
if (newformtime.Visible == true)<br />
{<br />
timeToolStripMenuItem.Checked = false;<br />
newformtime.Visible = false;<br />
}<br />
else if (newformtime.Visible == false)<br />
{<br />
timeToolStripMenuItem.Checked = true;<br />
newformtime.Visible = true;<br />
}<br />
}<br />
<br />
Form2 newForm2 = new Form2();<br />
private void button11_Click(object sender, EventArgs e)<br />
{<br />
newForm2.Visible = true;<br />
}<br />
<br />
<br />
private void button2_Click(object sender, EventArgs e)<br />
{<br />
if (newCalender.Visible == true)<br />
{<br />
calenderToolStripMenuItem.Checked = false;<br />
newCalender.Visible = false;<br />
}<br />
else if (newCalender.Visible == false)<br />
{<br />
calenderToolStripMenuItem.Checked = true;<br />
newCalender.Visible = true;<br />
} <br />
}<br />
<br />
<br />
private void button3_Click(object sender, EventArgs e)<br />
{<br />
if (newAlarm.Visible == true)<br />
{<br />
alarmToolStripMenuItem.Checked = false;<br />
newAlarm.Visible = false;<br />
}<br />
else if (newAlarm.Visible == false)<br />
{<br />
alarmToolStripMenuItem.Checked = true;<br />
newAlarm.Visible = true;<br />
}<br />
}<br />
<br />
<br />
private void button4_Click(object sender, EventArgs e)<br />
{<br />
if (newSRLS.Visible == true)<br />
{<br />
sRLSToolStripMenuItem.Checked = false;<br />
newSRLS.Visible = false;<br />
}<br />
else if (newSRLS.Visible == false)<br />
{<br />
sRLSToolStripMenuItem.Checked = true;<br />
newSRLS.Visible = true;<br />
}<br />
}<br />
<br />
<br />
private void button6_Click(object sender, EventArgs e)<br />
{<br />
if (newSearch.Visible == true)<br />
{<br />
searchToolStripMenuItem.Checked = false;<br />
newSearch.Visible = false;<br />
}<br />
else if (newSearch.Visible == false)<br />
{<br />
searchToolStripMenuItem.Checked = true;<br />
newSearch.Visible = true;<br />
}<br />
}<br />
<br />
<br />
private void button7_Click(object sender, EventArgs e)<br />
{<br />
if (newNote.Visible == true)<br />
{<br />
noteToolStripMenuItem.Checked = false;<br />
newNote.Visible = false;<br />
}<br />
else if (newNote.Visible == false)<br />
{<br />
noteToolStripMenuItem.Checked = true;<br />
newNote.Visible = true;<br />
}<br />
}<br />
<br />
<br />
private void button9_Click(object sender, EventArgs e)<br />
{<br />
if (newQuickLaunch.Visible == true)<br />
{<br />
quickLaunchToolStripMenuItem.Checked = false;<br />
newQuickLaunch.Visible = false;<br />
}<br />
else if (newQuickLaunch.Visible == false)<br />
{<br />
quickLaunchToolStripMenuItem.Checked = true;<br />
newQuickLaunch.Visible = true;<br />
}<br />
}<br />
<br />
private void pictureBox2_Click(object sender, EventArgs e)<br />
{<br />
<br />
}<br />
<br />
private void exitToolStripMenuItem_Click(object sender, EventArgs e)<br />
{<br />
this.Close();<br />
}<br />
<br />
private void notifyIcon1_DoubleClick(object sender, EventArgs e)<br />
{<br />
this.Show();<br />
}<br />
<br />
private void timeToolStripMenuItem_Click(object sender, EventArgs e)<br />
{<br />
timeToolStripMenuItem.Checked = true;<br />
<br />
<br />
Settings.Default["timecheck"] = timeToolStripMenuItem.Checked;<br />
Settings.Default.Save();<br />
}<br />
<br />
private void calenderToolStripMenuItem_Click(object sender, EventArgs e)<br />
{<br />
<br />
calenderToolStripMenuItem.Checked = true;<br />
<br />
<br />
Settings.Default["calendercheck"] = calenderToolStripMenuItem.Checked;<br />
Settings.Default.Save();<br />
}<br />
<br />
private void alarmToolStripMenuItem_Click(object sender, EventArgs e)<br />
{<br />
<br />
alarmToolStripMenuItem.Checked = true;<br />
<br />
<br />
Settings.Default["alarmcheck"] = alarmToolStripMenuItem.Checked;<br />
Settings.Default.Save();<br />
}<br />
<br />
private void sRLSToolStripMenuItem_Click(object sender, EventArgs e)<br />
{<br />
sRLSToolStripMenuItem.Checked = true;<br />
<br />
<br />
Settings.Default["srlscheck"] = sRLSToolStripMenuItem.Checked;<br />
Settings.Default.Save();<br />
}<br />
<br />
private void searchToolStripMenuItem_Click(object sender, EventArgs e)<br />
{<br />
searchToolStripMenuItem.Checked = true;<br />
<br />
<br />
Settings.Default["searchcheck"] = searchToolStripMenuItem.Checked;<br />
Settings.Default.Save();<br />
}<br />
<br />
private void noteToolStripMenuItem_Click(object sender, EventArgs e)<br />
{<br />
noteToolStripMenuItem.Checked = true;<br />
<br />
<br />
Settings.Default["notecheck"] = noteToolStripMenuItem.Checked;<br />
Settings.Default.Save();<br />
}<br />
<br />
private void quickLaunchToolStripMenuItem_Click(object sender, EventArgs e)<br />
{<br />
quickLaunchToolStripMenuItem.Checked = true;<br />
<br />
<br />
Settings.Default["quickLaunchcheck"] = quickLaunchToolStripMenuItem.Checked;<br />
Settings.Default.Save();<br />
}<br />
<br />
private void CMS_CheckChanged(object sender, EventArgs e)<br />
{<br />
foreach (ToolStripItem item in ((ToolStripDropDownItem)sender).Owner.Items)<br />
{<br />
if (item.GetType() == typeof(ToolStripMenuItem))<br />
{<br />
if (item == sender)<br />
((ToolStripMenuItem)item).Checked = true;<br />
else<br />
((ToolStripMenuItem)item).Checked = false;<br />
}<br />
}<br />
}<br />
<br />
}<br />
}
And in the program.cs I get this error
An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll
On this code
Application.Run(new Form1());
|
|
|
|
|
This is not your whole code - this is only Form1. My suspicion is that you might have a problem in one of the following lines:
Note newNote = new Note();
Search newSearch = new Search();
SRLS newSRLS = new SRLS();
Alarm newAlarm = new Alarm();
QuickLaunch newQuickLaunch = new QuickLaunch();
Calender newCalender = new Calender();
Time newformtime = new Time(); To prove this, you need to set a breakpoint in your Form_Load to see if you ever actually hit the Form_Load event. If you get the exception beforehand, then it's likely that your problem is in there (and the problem is that you have something that is recursively calling the same method).
Now, your coding style - it's never a good idea to leave default names for items you have any form of interaction with in your code, so you should rename things like button1, etc, to something much more meaningful. Also, you could condense a lot of your methods down. Take this one:
if (newAlarm.Visible == true)
{
alarmToolStripMenuItem.Checked = false;
newAlarm.Visible = false;
}
else if (newAlarm.Visible == false)
{
alarmToolStripMenuItem.Checked = true;
newAlarm.Visible = true;
} That could be rewritten more succinctly (and clearly) as:
newAlarm.Visible = !newAlarm.Visible;<br />
alarmToolStripMenuItem.Checked = newAlarm.Visible; You could get terser than that, but this is fairly clear in what it does.
|
|
|
|
|
Firstly a few presentation points:
If you ever post code again, use the "code block" and "inline code" buttons differently.
You used "inline code":
private void CMS_CheckChanged(object sender, EventArgs e)<br />
{<br />
foreach (ToolStripItem item in ((ToolStripDropDownItem)sender).Owner.Items)<br />
{<br />
if (item.GetType() == typeof(ToolStripMenuItem))<br />
{<br />
if (item == sender)<br />
((ToolStripMenuItem)item).Checked = true;<br />
else ((ToolStripMenuItem)item).Checked = false;<br />
}<br />
}<br />
}
If you had used "code block" instead it would have preserved the formatting:
private void CMS_CheckChanged(object sender, EventArgs e)
{
foreach (ToolStripItem item in ((ToolStripDropDownItem)sender).Owner.Items)
{
if (item.GetType() == typeof(ToolStripMenuItem))
{
if (item == sender)
((ToolStripMenuItem)item).Checked = true;
else ((ToolStripMenuItem)item).Checked = false;
}
}
} See how much easier it is to read?
There is a "Preview" button at the bottom - try it and see if it looks readable!
Also, don't post your whole file - just the relevant bits! Otherwise we have to scroll through the whole lot to get to the reply button - this discourages people from bothering...
Secondly general good things to do in code:
In the example above (and others) you are casting the sender parameter directly to a ToolStripDropDownItem . What happens if you re-use the method? Answer: your program crashes with a "cannot convert" error. Instead, always check before you cast. Either use:
if (sender is ToolStripDropDownItem_
{
ToolStripDropDownItem item = (ToolStripDropDownItem) sender;
...
} or
ToolStripDropDownItem item = sender as ToolStripDropDownItem;
if (item != null)
{
...
} I prefer the later as it makes the null check explicit.
This is part of what is called "Defensive Programming" and trust me, it is something well worth getting into the habit of!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
systemerror121 wrote: Form2 newForm2 = new Form2();
private void button11_Click(object sender, EventArgs e)
{
newForm2.Visible = true;
}
I bet you have same kind of code (like the one given below) in Form2 also.
Form1 newForm1 = new Form1();
private void button11_Click(object sender, EventArgs e)
{
newForm1.Visible = true;
}
"Never put off until run time what you can do at compile time."
- David Gries, in "Compiler Construction for Digital Computers", circa 1969.
|
|
|
|
|
I'm not looking into your code, as you're abusing the CODE and PRE tags: regular text needs neither, multi-line code snippets need PRE tags so indentation gets preserved.
The most popular way to create an SOE is by referring to some property inside its own getter/setter.
|
|
|
|
|
It has been a while since I did winForms, but shouldn't you actually implement InitializeComponent if you are going to call it in the constructor?
Also give your controls reasonable names. Unless your app is replicating a phone or a calculator you should never have things like button7 and button9.
|
|
|
|
|
The WinForms designer implemented InitializeComponent in a Form1.Designer.cs source file, which is why you don't see it in the OP's source. Notice that the class is declared as partial - that allows a single class implementation to span multiple source files.
|
|
|
|
|
You probably have the Form2 creating a new Form1 but you didn't post that code.
A word of advice, next time put the question/problem/error before the code. At first I couldn't see what you were asking, if anything!
|
|
|
|
|
Well, your program contains an infinite (or too deep) recursion. We cannot really tell where, since you have not posted your whole program. As adviced above, set breakpoints in the constructors at InitializeComponent of both forms you are instantiating. Then, step into the code and observe what is happening there... Have you manually modified the IDE generated InitializeComponent method? Have you used Designer to put your form together or have you done it manually?
By the way (to the english native speakers): does the verb "to squrid up" really exist?
|
|
|
|
|
I want to create ' a button ' on Excel 2007 ribbon, File tab, Font group to change Font of select cells.
If possible I want to create Add-In file in Visual Studio 2010/ VS2008.
|
|
|
|
|
And what is the problem you have with this task?
If you want to add a button to an existing group on existing tab, I think it would be easier to do it in VBA.
Don't forget to rate answer, that helped you. It will allow other people find their answers faster.
|
|
|
|
|
|
sardar.nale wrote: classes for video chat
You want to take online night classes, or do you want us to do your work for you? Tell you what, you write an efficient routing algorithm that can load and manipulate 120GB worth of major and minor road networks for a wide variety of vehicle types, allowing varying levels of speed restrictions per vehicle type, in realtime, and I'll write your video chat classes. Do we have a deal?
|
|
|
|
|
|