佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

楼主: chrizyuen2

[挑战自我] 欢迎任何C#疑难杂症(编写完整软件除外)

  [复制链接]
 楼主| 发表于 9-2-2011 05:17 PM | 显示全部楼层
想问一下。。。 为什么要写 _bitmap ,而不要直接写 bitmap ? 还有m_shouldPaint 而不要mshouldPaint?? ...
麟 发表于 9-2-2011 04:48 PM


为什么不直接写bitmap
1)有一天,你project 超过10,000lines , 你要找某字眼(ctrl+shift+f) 的时候,你就知道痛苦是什么。。。
2)跟标准就没错。
回复

使用道具 举报


ADVERTISEMENT

发表于 9-2-2011 05:20 PM | 显示全部楼层
本帖最后由 麟 于 9-2-2011 05:22 PM 编辑

结论是,现在不用放underscore也不要紧,是吗?当然放了比较好!!

如何换特别的cursor? 如何加特别的cursor进去 visual C# 2005???
回复

使用道具 举报

 楼主| 发表于 9-2-2011 05:22 PM | 显示全部楼层
结论是,现在不用放underscore也不要紧,是吗?
如何换特别的cursor? 如何加特别的cursor进去 visual C# ...
麟 发表于 9-2-2011 05:20 PM


visual C#(VS IDE)支持unicode,你要打中文都可以


  1. private int 加法(int 分数1,int 分数2)
  2. {   
  3. return 分数1+分数2;
  4. }
复制代码
回复

使用道具 举报

 楼主| 发表于 9-2-2011 05:24 PM | 显示全部楼层
回复

使用道具 举报

发表于 9-2-2011 05:26 PM | 显示全部楼层
visual C#(VS IDE)支持unicode,你要打中文都可以
chrizyuen2 发表于 9-2-2011 05:22 PM


cursor 哦?老鼠的箭头喔?
回复

使用道具 举报

 楼主| 发表于 9-2-2011 05:30 PM | 显示全部楼层
回复 85#

不能还得了?
  1. // hourglass cursor
  2. Cursor.Current = Cursors.WaitCursor;
  3. try
  4. {
  5.   Thread.Sleep(5000);  // wait for a while
  6. }
  7. finally
  8. {
  9.   Cursor.Current = Cursors.Default;
  10. }
复制代码
回复

使用道具 举报

Follow Us
发表于 9-2-2011 05:41 PM | 显示全部楼层
这些是本来就有了的,我是说我们是否可以放自己画的图画为箭头?
因为,我写的painter里(好像是你写比较多),我加了一个“橡皮擦”,

我是否可以做成像 ms paint 里的“橡皮擦”?
“橡皮擦”模式时,箭头在白纸上是一个四方格。还可以加减“四方格”(箭头)的size。“橡皮擦”越大,“四方格”就越大。可能吗?
回复

使用道具 举报

 楼主| 发表于 9-2-2011 05:48 PM | 显示全部楼层
回复 87#

custom cursor  = http://www.switchonthecode.com/tutorials/csharp-tutorial-how-to-use-custom-cursors在bitmap graphics , 没有橡皮擦,这样东西..
图上background颜色,盖过就是了.
回复

使用道具 举报


ADVERTISEMENT

发表于 9-2-2011 06:06 PM | 显示全部楼层
懂了!!
你很神
回复

使用道具 举报

 楼主| 发表于 9-2-2011 06:17 PM | 显示全部楼层
懂了!!
你很神
麟 发表于 9-2-2011 06:06 PM


  你问的东西还很基本。。。
回复

使用道具 举报

发表于 9-2-2011 07:41 PM | 显示全部楼层
本帖最后由 麟 于 9-2-2011 07:53 PM 编辑
  1. namespace WindowsApplication1
  2. {     
  3. public struct IconInfo   
  4. {        
  5. public bool fIcon;        
  6. public int xHotspot;        
  7. public int yHotspot;        
  8. public IntPtr hbmMask;        
  9. public IntPtr hbmColor;   
  10. }
  11.    
  12. public partial class Form2 : Form   
  13. {   
  14. [DllImport("user32.dll")]        
  15. public static extern IntPtr CreateIconIndirect(ref IconInfo icon);
  16.         
  17. [DllImport("user32.dll")]  [return: MarshalAs(UnmanagedType.Bool)]        
  18. public static extern bool GetIconInfo(IntPtr hIcon, ref IconInfo pIconInfo);
  19.         
  20. public static Cursor CreateCursor(Bitmap bmp, int xHotSpot, int yHotSpot)
  21. {        
  22. IconInfo tmp = new IconInfo();               
  23. GetIconInfo(bmp.GetHicon(), ref tmp);               
  24. tmp.xHotspot = xHotSpot;               
  25. tmp.yHotspot = yHotSpot;               
  26. tmp.fIcon = false;               
  27. return new Cursor(CreateIconIndirect(ref tmp));
  28. }      

  29. private void pictureBox1_MouseMove(object sender, MouseEventArgs e)        
  30. {
  31. this.Text = "Cursor Test";           
  32. Bitmap E_bitmap = new Bitmap(140, 25);         
  33. Graphics g = Graphics.FromImage(E_bitmap);           
  34. using (Font f = new Font(FontFamily.GenericSansSerif, 20))              
  35. g.DrawString("[]", f, Brushes.Green, 0, 0);   
  36. this.Cursor = CreateCursor(E_bitmap, 5, 5);
  37.          
  38. E_bitmap.Dispose();        
  39. }  
  40. }
  41. }
复制代码


我想在pictureBOX1里用那特别的cursor“[]”而已。

1。想问在 E_bitmap.Dispose() 过后,为什么cursor 不会换回去default cursor?
2。根据我的code,cursor不是应该只在pictureBOX1里用那特别的cursor“[]” 吗? 

可是现在我的cursor一直都是“[]”,在pictureBOX1外也一样。
回复

使用道具 举报

发表于 9-2-2011 08:03 PM | 显示全部楼层
我忘了换
  1. pictureBox1.Cursor = CreateCursor(E_bitmap, 5, 5);
复制代码
谢了,能了!!
回复

使用道具 举报

发表于 21-3-2011 04:55 PM | 显示全部楼层
如何 create 一个 icon 在 deskstop 直接 run program?不用一直开c# ..谢!
回复

使用道具 举报

 楼主| 发表于 21-3-2011 06:25 PM | 显示全部楼层
回复 93#

汗。。。我劝你去找visual studio书看看。

1)Right click Project->Properties  
2) Application -> Icons:
3) Rebuild target -> Release.
4) Project Folder\Bin\Release
回复

使用道具 举报

发表于 31-3-2011 04:25 PM | 显示全部楼层
本帖最后由 木村拓栽 于 31-3-2011 04:37 PM 编辑

还有user enter date的部分也不会work(问题应该出现在application的 37)
麻烦你们了

application
  1. import javax.swing.JOptionPane;
  2. import java.text.DateFormat;
  3. import java.text.SimpleDateFormat;

  4. public class WorkerApp
  5. {
  6.         public static void main(String args[])
  7.         {      
  8.                 DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
  9.       
  10.                 //hourly worker and salesman object
  11.                
  12.       
  13.                 Salesman s=new Salesman();

  14.                 //declaration
  15.                 String name,id,hdate;
  16.                 double basicpay=0;
  17.                 double monthsale=0;
  18.                 double commission=0.0;
  19.                 String answer;
  20.                 double total=0.0;



  21.                 do{

  22.                         //input the worker information
  23.                         id=JOptionPane.showInputDialog("Enter worker ID:");
  24.                         name=JOptionPane.showInputDialog("Enter worker name:");
  25.                
  26.                        
  27.                         do{      
  28.                                 hdate=JOptionPane.showInputDialog("Enter hire date:");
  29.                               
  30.                
  31.                           if(!df.format(df).equals(hdate))
  32.                    {
  33.                       JOptionPane.showMessageDialog(null, " Input invalid\nPlease enter a positive integer.","Error input",JOptionPane.ERROR_MESSAGE);
  34.                         }
  35.                
  36.                
  37.                         }while(!df.format(df).equals(hdate));
  38.       

  39.       
  40.                         //input the hourly worker information
  41.                         basicpay=Double.parseDouble(JOptionPane.showInputDialog("Enter basic pay :"));
  42.                         monthsale=Double.parseDouble(JOptionPane.showInputDialog("Enter total sales:"));
  43.                         commission=Double.parseDouble(JOptionPane.showInputDialog("Enter commission :"));
  44.                        
  45.                        
  46.                        

  47.                         s.setMonthsale(monthsale);
  48.                         s.setBasicpay(basicpay);
  49.                         s.setCommission(commission);
  50.                         s.setId(id);
  51.                         s.setHdate(hdate);
  52.                         s.setName(name);
  53.                         total=s.CalculateSalary();//calculate hourly worker salary
  54.                        
  55.                         //if the user choose salesman object
  56.                        

  57.                        


  58.                 //display the worker id, name, and salary.
  59.       
  60.                 JOptionPane.showMessageDialog(null,"Employee Name: "+s.getName()+
  61.                                                                                         "\nEmployee ID: "+s.getId()+
  62.                                                                                         "\nEmployee Hired Date: "+s.getHdate()+
  63.                                                                                         "\nBasic Salary: "+s.getBasicpay()+
  64.                                                                                         "\nCommission rate: "+s.getCommission()+
  65.                                                                                         "\nMonthly Sales: "+s.getMonthsale()+
  66.                                                                                        
  67.                                                                                         "\n\nNet Salary: "+total);

  68.                 //ask the user whether continue or not
  69.                 answer=JOptionPane.showInputDialog("Do you want to continue?(yes/no)");

  70.                 }while(answer.equals("yes"));//Whether the user decide when to stop

  71.       

  72.         }}
复制代码



class



  1. public class Salesman extends Worker
  2. {

  3.     //declaration
  4.     private double basicpay;
  5.     private double monthsale;
  6.     public double commission;
  7.    
  8.     //two overloaded constructors
  9.     public Salesman()
  10.     {
  11.    
  12.         basicpay=0.0;
  13.         monthsale=0.0;
  14.         commission=0.0;
  15.     }
  16.     public Salesman(String i,String n,String d,double basicpay,double monthsale,double commission)
  17.     {
  18.    
  19.         this.basicpay=basicpay;
  20.         this.monthsale=monthsale;
  21.         this.commission=commission;
  22.     }

  23.     //mutator method
  24.     public void setBasicpay(double b)
  25.     {
  26.         basicpay=b;
  27.     }
  28.     public void setMonthsale(double s)
  29.     {
  30.         monthsale=s;
  31.     }
  32.     public void setCommission(double c)
  33.     {
  34.         commission=c;
  35.     }

  36.     //accessor method
  37.     public double getBasicpay()
  38.     {
  39.         return basicpay;
  40.     }
  41.     public double getMonthsale()
  42.     {
  43.         return monthsale;
  44.     }
  45.     public double getCommission()
  46.     {
  47.         return commission;
  48.     }

  49.     //implementation of abstract method
  50.     //The salary for a salesman is calculated as the basic pay plus commission.
  51.     //The commission is calculated based on the rate given for the sales made.
  52.     public double CalculateSalary()
  53.     {
  54.         return basicpay+(monthsale*(commission/100.0));
  55.     }
  56.    

  57. }//end class Salesman
复制代码




subclass



  1. public abstract class Worker
  2. {
  3.     //declaration
  4.     protected String name;
  5.     protected String id;
  6.     protected double basicpay;
  7.     protected String hdate;
  8.    
  9.    
  10.     //two overloaded constructors
  11.     protected Worker()
  12.     {
  13.         name=null;
  14.         hdate=null;
  15.         id=null;
  16.         basicpay=0.0;
  17.     }
  18.     public Worker(String name,String hdate,String id,double basicpay)
  19.     {
  20.         this.name=name;
  21.         this.hdate=hdate;
  22.         this.id=id;
  23.         this.basicpay=basicpay;
  24.     }//end three-argument Worker constructor

  25.     //mutator method
  26.     public void setName(String n)
  27.     {
  28.         name=n;
  29.     }
  30.     public void setHdate(String d)
  31.     {
  32.         hdate=d;
  33.     }
  34.     public void setBasicpay(int s)
  35.     {
  36.         basicpay=s;
  37.     }
  38.     public void setId(String i)
  39.     {
  40.         id=i;
  41.     }


  42.     //accessor method
  43.     public String getName()
  44.     {
  45.         return name;
  46.     }
  47.     public String getHdate()
  48.     {
  49.         return hdate;
  50.     }
  51.     public double getBasicpay()
  52.     {
  53.         return basicpay;
  54.     }
  55.     public String getId()
  56.     {
  57.         return id;
  58.     }

  59.     //abstract method
  60.     public abstract double CalculateSalary();

  61. }//end class worker
复制代码
回复

使用道具 举报

 楼主| 发表于 31-3-2011 04:38 PM | 显示全部楼层
本帖最后由 chrizyuen2 于 31-3-2011 04:40 PM 编辑

尝试给个 namespace.
也加入classpath.
PS: 我随便说的,等我回家才用java testing.
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 1-4-2011 07:16 PM | 显示全部楼层
本帖最后由 chrizyuen2 于 1-4-2011 07:18 PM 编辑

回复 95# 木村拓栽

好不容易才install了eclipse.
下次java别post来这里, 我很难下台

  public static boolean isValidDateStr(String date, String format) {   
  try {      
     SimpleDateFormat sdf = new SimpleDateFormat(format);      sdf.setLenient(false);      sdf.parse(date);   
   } catch (ParseException e) {      return false;    }   
     catch (IllegalArgumentException e) {      return false;    }   
   return true;   
}

http://www.rgagnon.com/javadetails/java-0099.html
回复

使用道具 举报

发表于 1-4-2011 09:47 PM | 显示全部楼层
回复  木村拓栽

好不容易才install了eclipse.
下次java别post来这里, 我很难下台

  publi ...
chrizyuen2 发表于 1-4-2011 07:16 PM

忘了回复你,我成功了。。。。
功课今天就是due date了

不过还是要谢谢你。。
回复

使用道具 举报

发表于 14-4-2011 03:12 AM | 显示全部楼层
i wan put the value into radio button (value is in array)
请问要怎样放进radiobutton??
回复

使用道具 举报

 楼主| 发表于 14-4-2011 09:22 AM | 显示全部楼层
i wan put the value into radio button (value is in array)
请问要怎样放进radiobutton??
Iandhim 发表于 14-4-2011 03:12 AM


一组的radiobutton, 其中只有一个可以被选择。 所以,大家都是用enum,从来不用array我觉得你是说checkbox吧。
loop你的array, 一个个set, 那样而已。


对了,那是怎样的array?  int[]? string[], list<string>?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 14-10-2025 01:55 PM , Processed in 0.184416 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表