|
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]:.
|
|
|
|
|
You'll need to have an assembly with an entry point. Have another EXE assembly that also depends upon your singleton and forces it to create an instance of itself. In my sample, this was the same executable. Just make another executable that doesn't load your win app - just the singleton.
-----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 want to know any class in .net able to convert a byte array (eg. 4 bytes) into a 32-bytes floating point data?
if not, i need to handle by myself with bitrise operation.
any help?
thanks,
jim
|
|
|
|
|
BitConverter.ToSingle .
-----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 want to be able to give read/write permissions on certain AD classes to certain accounts.
For instance, I want an account (say user1) to be able to create serviceConnectionPoint child objects. Another example would be to grant an account write access to mS-SQL-SQLServer class.
Any ideas how to do this in C#?
Thanks in advance.
Nidhi
|
|
|
|
|
You can access security only via Interop of adsi32 i think. There is no file security for .NET. I think there is a port in gotdotnet somewhere but you need to fell brave to put that under production. How would you be using mS-SQL-SQLServer?
Cheers,
Erick
|
|
|
|
|
Yes, I can use ADSI interop, but how do I set permissions on a class?
I shall be pulishing some application specific info in the keywords property of mS-SQL-SQLServer.
Regards,
Nidhi
|
|
|
|
|
I'm having a wierd issue where i run a query in a thread and the while(Connection.read()) duplicates my results. Anyone else have this issue? For isntance if I have TestTable with the following values:
TestID
1
2
3
It will console.writeline
1
1
2
2
3
3
Below is sample code:
private void button3_Click(object sender, System.EventArgs e)
{
ThreadStart DBThread = new ThreadStart(StartDBDelegate) ;
Thread DB = new Thread(DBThread) ;
DB.Start();
}
public void StartDBDelegate)()
{
Invoke(new UpdateLoadTableDelegate(RunUpdateNow));
}
public void RunUpdateNow()
{
string source =
"server=testserver;uid=testuid;pwd=testpassword;database=TestDB";
string selectconn1 = "SELECT TestID as dbTestID FROM TestTable"
SqlConnection conn1 = new SqlConnection(source);
conn1.Open();
SqlCommand executeconn1 = new SqlCommand(selectconn1,conn1);
SqlDataReader Connection1 = executeconn1.ExecuteReader();
while(Connection1.Read())
{
Console.WriteLine (Connection1[0].ToString())
}
}
I can reduce this menace by doing the following to the while loop, although I shouldnt have to do this...this is really bugging me. It doesnt do this outside of the thread.
string strTestID = "";
while(Connection1.Read())
{
if(strTestID != Connection1[0].ToString()))
{
Console.WriteLine (Connection1[0].ToString())
strTestID = Connection1[0].ToString());
}
}
|
|
|
|
|
I am currently trying to learn C# and looking at some of the classes available, I have come across a snag. I'm looking at the TimeZone class in the System namespace. It has a static function CurrentTimeZone which is fine, but what if i want to work with a different TimeZone? How do I specify that I wish to work in US Mountain Standard Time or AUS Eastern Standard Time ?
Thanx in advance.
The jubjub
|
|
|
|