|
Heath Stewart wrote:
this is just laziness bolstered by IntelliSense
Thats just what I was thinking )
IntelliSense is a great idea but it does almost remove any need to remember class and method names!
James Simpson
Web Developer
imebgo@hotmail.com
P S - This is what part of the alphabet would look like if Q and R were eliminated Mitch Hedberg
|
|
|
|
|
The following will work as well.
string full_path = @"C:\Folder\New\FileName.jpg";
string file_name = full_path.Substring(full_path.LastIndexOf(@"\") + 1);
-Nick Parker
DeveloperNotes.com
|
|
|
|
|
Until you use this on a different platform. You should use Path.GetFileName . If you want to do such things yourself, be sure to at least use
Path.DirectorySeparatorChar<br /> .
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi
Simple question: How can I block the user from moving a form around (i.e. making it stay in the same place all the time)?
I can't find a property/method for it in System.Windows.Forms.Form.
Naturally, I can just create an eventhandler for the LocationChanged event or similiar - but I'm looking for something a little more simple, since there are a lot of forms in our application which are all created by a form factory class.
Thanks for your help,
Mads
|
|
|
|
|
If it shouldn't be moveable then it shouldn't have a caption either. If make it FormBorderStyle.None it will have no caption or border and the user will not be able to drag it.
Obviously this is only suitable for special purpose applications that are designed to work on a dedicated computer, like a point of sale machine or kiosk. If you are writing a conventional application you should not be making for forms unmovable in the first place, that is exceedingly rude.
-Blake
|
|
|
|
|
FormBorderStyle.None is not good since that will remove both the caption and the border <=> the form will look rather silly.
Instead, our designgroup (sigh!) got another idea. They want the forms to have a caption with only a minimize button (i.e. no maximize and close buttons). Does any of you know if this is possible?
I have found e.g. form.MinimizeBox = false - but that property doesn't remove the button, it only disable it.
Again thanks for your help, Mads
BTW: It is actually a point of sale application, so we are not being rude
|
|
|
|
|
The whole point is, if you have a standard caption across the top of a form then then user is going to assume he can grab and drag it to move the form. Displaying a caption but then refusing to drag is just a way to piss off the user.
Use FormBorderStyle.None as I said and draw your own psuedo-caption across the top, with whatever controls you do or don't want in it. Do not give the user standard widgets and then make them not work, that is horrible UI design.
-Blake
|
|
|
|
|
Hello, Sir
I have a class that has two ImageList and two ImageIndex property as the code below.
My problem is when set propertyGrid.SelectedObject equal to my class instance
indexA and indexB will show the same list of images on the propertyGrid.
How to make the indexA show list of images in _imagelistA
and make the indexB show list of images in _imagelistB ?
Thank You.
Sorry for bad English.
public ImageList imagelistA
{
get { return _imagelistA;}
set { _imagelistA = value; }
}
[TypeConverter(typeof(ImageIndexConverter)), Editor("System.Windows.Forms.Design.ImageIndexEditor, System.Design,Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",typeof(System.Drawing.Design.UITypeEditor))]
public int indexA
{
get { return _indexA; }
set { _indexA = value; }
}
public ImageList imagelistB
{
get { return _imagelistB;}
set { _imagelistB = value; }
}
[TypeConverter(typeof(ImageIndexConverter)), Editor("System.Windows.Forms.Design.ImageIndexEditor, System.Design,Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",typeof(System.Drawing.Design.UITypeEditor))]
public int indexB
{
get { return _indexB; }
set { _indexB = value; }
}
|
|
|
|
|
I already replied to you about this. If you don't like the answer, sorry...but tough. The TypeConverter you're trying to use looks for the first property that returns an ImageList . That's why you see the same ImageList for both indexes. You're going to have to write your own. There's no way around it.
Read the documentation for the TypeConverter . It's actually not that hard. If nothing else, teach yourself IL and use ildasm.exe to look at the ImageIndexEditor and ImageIndexConverter (or use a decompiler like .NET Reflector) and change what you have to into your own class, attributing your property as you did above except with your own converter and editor (use the typeof operator if they are in the same assembly).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I have 2 forms. The application enters on frmMain. Then I want to show frmSetup and hide frmMain.
it seems pretty straight forward, but i can not get frmMain to hide.
FormSetup frmSetup = new FormSetup();<br />
frmSetup.Show();<br />
frmMain.Hide();
is there anything i'm missing here?
|
|
|
|
|
Is that code placed in frmMain_Load? .NET shows a form after calling the Load-event, so hiding a form on load is ignored.
|
|
|
|
|
m kinda stuck here....m trying to get all numbers between 1 and 1000 which are all prime....
i am here
for(int i = 1 ; i < 301 ; i++)<br />
{<br />
for(int j = 1 ; j < 301 ; j++)<br />
{<br />
if(i <= j)<br />
{<br />
int remainder = i % j;<br />
}<br />
}<br />
}
but i am kinda getting screwed up in the logic..i did the same thing in C 2 years ago.....
but now come to C#...i forgot how i did it....
Have a Super Blessed Day!
-------------------------
For God has not given us a spirit of fear, but of power and of love and of a sound mind.
2 Timothy 1:7
"For God so loved the world that He gave His only begotten Son, that whoever believes in Him should not perish but have everlasting life."
John 3:16
"Therefore you also be ready, for the Son of Man is coming at an hour you do not expet."
Luke 12:40
|
|
|
|
|
There are much better algorithms now, but the simplest one is:
using System;
class Prime {
static void Main() {
for(int i = 2; i < 1000; ++i) {
bool prime = true;
for(int j = 2; j < (int)Math.Ceiling(Math.Sqrt(i)); ++j) {
if (i % j == 0) {
prime = false;
break;
}
}
if (prime) Console.WriteLine(i);
}
}
}
-Blake
|
|
|
|
|
see this line:
for(int j = 2; j < (int)Math.Ceiling(Math.Sqrt(i)); ++j)
u just forgot to add equal sing
for(int j = 2; j <= (int)Math.Ceiling(Math.Sqrt(i)); ++j)
|
|
|
|
|
Indeed you are correct - all those perfect squares just became prime with my code.
-Blake
|
|
|
|
|
yep, but ur code is still not bad
|
|
|
|
|
*chuckles* Well, it's hardly the number field sieve[^] but he only wanted primes less than 1000 so that seemed a little excessive.
-Blake
|
|
|
|
|
this is a one possible solution, u can get a prime number.
not a best way but it works
<br />
using System;<br />
<br />
namespace ConsoleApplication1<br />
{<br />
class Prime<br />
{<br />
[STAThread]<br />
static void Main()<br />
{<br />
for(int i = 2; i < 1010; ++i) if( isPrime(i) ) Console.WriteLine(i);<br />
System.Console.Read();<br />
}<br />
<br />
public static bool isPrime(int number)<br />
{<br />
if(number == 2) return true;<br />
<br />
if(number < 2 || number % 2 == 0) return false;<br />
<br />
for(int i = 3; i <= (int)Math.Sqrt(number); i += 2)<br />
if(number % i == 0) return false;<br />
<br />
return true;<br />
}<br />
}<br />
}
good luck with this code, i hope it helps u.
|
|
|
|
|
Hallo, I'd like to know how can I change windows form menu aspect:
I know how to shape a form: drawing a bmp and than use the trasparentkey and so on...
I think that to apply a skin you should draw a good bmp isn't it?
But, how can I change the graphics of menu?
Thank you very much
|
|
|
|
|
Owner drawn Windows. It's not near as easy as what you're doing for forms (which, btw, is very inefficient - you'd be better of specifying a Window region the old-school way if performance is important).
At the high-level, you can set MenuItem.OwnerDraw to true and handle painting that way. You can, of course, always go low-level and P/Invoke a lot of Win32 APIs, using the Menu.Handle property to get the HMENU for the menu item.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Anyone know if there's a way to open up a new instance of Internet Explorer within C#. I have a web app (all done in C# code, trying to avoid ASP/C# scripting and such if at all possible) that currently takes in data and runs a query on that data. *Ideally*, I'd like to take the result of that query, and have it post to a new web form.
<---signature--->
Your kid gets into Duke.
You pay the tuition.
That tuition goes into my checking account.
My money in my checking account goes into beer, porn, and other such fun. Thank you
|
|
|
|
|
1) C# is all server-side. To control the browser in such a way as to display a new form is client-side.
2) You don't even need to use any fancy javascript to do this. It's been possible since HTML 2.0 (if I remember right; 3.2 at the latest). Simply add a target attribute to your form like so:
<form runat="server" target="_blank">
<!-- blah blah blah -->
</form>
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi,
i would like to load a singleton class in my default app domain. But also create a new domain and use the same class type with a new instance/singleton.
How to do that?
.:[Greetz from Jerry Maguire]:.
|
|
|
|
|
This shouldn't be a problem. Locking against types to create singletons (as is common for determine if an instance already exists) is supposed to be context-bound. Being that the AppDomain is a separate context, this shouldn't pose a problem.
The following code fragment (that works) should prove it:
using System;
using System.IO;
using System.Reflection;
public class Test
{
public static void Main(string[] args)
{
Singleton.SayHello();
Singleton.SayHello();
if (!Singleton.Foo)
{
Console.WriteLine("Executing entry point in same AppDomain...");
AppDomain.CurrentDomain.ExecuteAssembly(
Assembly.GetEntryAssembly().Location);
}
if (AppDomain.CurrentDomain.FriendlyName != "New")
{
Console.WriteLine("Creating new AppDomain...");
AppDomain domain = AppDomain.CreateDomain("New",
AppDomain.CurrentDomain.Evidence);
domain.ExecuteAssembly(Assembly.GetEntryAssembly().Location);
}
}
}
public class Singleton
{
private TextWriter writer;
private Singleton()
{
Console.WriteLine("Creating new singleton instance...");
writer = Console.Out;
}
private static Singleton instance;
private static Singleton Instance
{
get
{
if (instance == null)
lock (typeof(Singleton))
if (instance == null)
instance = new Singleton();
return instance;
}
}
public static void SayHello()
{
Instance.writer.WriteLine("Hello, world!");
}
private bool foo = false;
public static bool Foo
{
get
{
if (!Instance.foo)
{
Instance.foo = true;
return false;
}
return true;
}
}
}
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi Heath,
thank you for your sample code.
Let's say i've got a WindowsApplication project. Than i have a class library project which defines the type with the singleton.
Now my WindowsApplication project references the class library assembly for "normal" use of singleton type.
Now i would like to create a new appdomain and create a new instance of my singleton class.
How to do that? The other "normal" instance is alive in the CurrentAppDomain.
.:[Greetz from Jerry Maguire]:.
|
|
|
|