By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,255 Members | 2,640 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,255 IT Pros & Developers. It's quick & easy.

The onpaint() is getting called before calculating the required parameters by listBox

P: 1
The onpaint() is getting called before calculating the required parameters by listBox1_SelectedIndexChanged function. I tried calling it at the end of this function. But of no use. Due to this issue only half of the diagram is getting painted,some lines are missing in the diagram.

Expand|Select|Wrap|Line Numbers
  1. private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
  2. {
  3. string str=listBox1.SelectedItem.ToString();
  4. string str1=null;
  5. if(treeView1.SelectedNode!=null)
  6. str1=treeView1.SelectedNode.FullPath.Replace("TreeNode: ","");
  7. string strdir=Directory.GetDirectoryRoot(listBox1.SelectedItem.ToString());
  8. string path=strdir+str1+str;
  9. StreamReader sr=null;
  10. StreamWriter sw=null;
  11. Double Surface=0;
  12. int comment=0;
  13. string profile=null;
  14. try
  15. {
  16. string str2=null,str3=null,str4=null;
  17. string strvb=null,strve=null,strvbr=null,strve1=null,strob=null,stroe=null,strobr=null;
  18. //string path=textBox7.Text;
  19. sr=new StreamReader(path);
  20. int d=0;
  21. int i=0;
  22. int linenum=0;
  23. while((str2=sr.ReadLine())!=null)
  24. {
  25. comment=str2.IndexOf("*");
  26. i++;
  27. if(i==3)
  28. {
  29. if(comment!=-1)
  30. {
  31. str3= str2.Remove(comment,str2.Length-comment);
  32. str4= str3.Trim();
  33. textBox1.Text=str4;
  34. }
  35. else
  36. textBox1.Text=str2;
  37. }
  38. if(i==4)
  39. {
  40. if(comment!=-1)
  41. {
  42. str3= str2.Remove(comment,str2.Length-comment);
  43. str4=str3.Trim();
  44. textBox4.Text=str4;
  45. }
  46. else
  47. textBox4.Text=str2;
  48. }
  49. if(i==6)
  50. {
  51. if(comment!=-1)
  52. {
  53. str3= str2.Remove(comment,str2.Length-comment);
  54. str4=str3.Trim();
  55. textBox2.Text=str4;
  56. }
  57. else
  58. textBox2.Text=str2;
  59. }
  60. if(i==7)
  61. {
  62. if(comment!=-1)
  63. {
  64. str3= str2.Remove(comment,str2.Length-comment);
  65. str4=str3.Trim();
  66. textBox6.Text=str4;
  67. }
  68. else
  69. textBox6.Text=str2;
  70. }
  71. if(i==8) 
  72. {
  73. if(comment!=-1)
  74. {
  75. str3= str2.Remove(comment,str2.Length-comment);
  76. str4=str3.Trim();
  77. textBox5.Text=str4;
  78. }
  79. else
  80. textBox5.Text=str2;
  81. }
  82. if(i==9) 
  83. {
  84. if(comment!=-1)
  85. {
  86. str3= str2.Remove(comment,str2.Length-comment);
  87. str4=str3.Trim();
  88. textBox3.Text=str4;
  89. }
  90. else
  91. textBox3.Text=str2;
  92. }
  93. if(i==10)
  94. {
  95. if(str2==" I")
  96. {
  97. profile="I";
  98. }
  99. else
  100. if(str2==" B")
  101. {
  102. //Graphics ge=this.CreateGraphics();
  103. //ge.Clear(Form1.ActiveForm.BackColor);
  104. profile="B";
  105. }
  106. else if(str=="C")
  107. {
  108. Bitmap img=new Bitmap("C-Sec.jpg");
  109. pictureBox1.Image=img;
  110. }
  111. else if(str=="L")
  112. {
  113. Bitmap img=new Bitmap("L-Sec.jpg");
  114. pictureBox1.Image=img;
  115. }
  116. else if(str=="M")
  117. {
  118. Bitmap img=new Bitmap("M-Sec.jpg");
  119. pictureBox1.Image=img;
  120. }
  121. else if(str=="T")
  122. {
  123. Bitmap img=new Bitmap("T-Sec.jpg");
  124. pictureBox1.Image=img;
  125. }
  126. else if(str=="U")
  127. {
  128. Bitmap img=new Bitmap("U-Sec.jpg");
  129. pictureBox1.Image=img;
  130. }
  131. }
  132. if(i==11)
  133. {
  134. str2.Trim();
  135. if(comment!=-1)
  136. {
  137. str3= str2.Remove(comment,str2.Length-comment);
  138. a=Double.Parse(str3);
  139. }
  140. else
  141. a=Double.Parse(str2);
  142. }
  143. //int j=a;
  144. if(i==12)
  145. {
  146. if(comment!=-1)
  147. {
  148. str3= str2.Remove(comment,str2.Length-comment);
  149. b=Double.Parse(str3);
  150. }
  151. else
  152. //label10.Text=str2;
  153. b=Double.Parse(str2);
  154. }
  155. if(i==13)
  156. {
  157. if(comment!=-1)
  158. {
  159. str3= str2.Remove(comment,str2.Length-comment);
  160. w=Double.Parse(str3);
  161. }
  162. else
  163. w=Double.Parse(str2);
  164. }
  165. if(i==14)
  166. {
  167. //label11.Text=str2;
  168. //textBox10.Text=str;
  169. if(comment!=-1)
  170. {
  171. str3= str2.Remove(comment,str2.Length-comment);
  172. c=Double.Parse(str3);
  173. }
  174. else
  175. c=Double.Parse(str2);
  176. }
  177. if(i==17)
  178. {
  179. if(comment!=-1)
  180. {
  181. str3= str2.Remove(comment,str2.Length-comment);
  182. str4=str3.Trim();
  183. textBox7.Text=str4;
  184. }
  185. else
  186. textBox7.Text=str2;
  187. }
  188. if(i==18)
  189. {
  190. if(comment!=-1)
  191. {
  192. str3= str2.Remove(comment,str2.Length-comment);
  193. str4=str3.Trim();
  194. textBox8.Text=str4;
  195. }
  196. else
  197. textBox8.Text=str2;
  198. }
  199. if(i==28)
  200. {
  201. strvb=str2;
  202. string strvbr1=strvb.Replace("v"," ");
  203. string strvbru=strvbr1.Replace("u"," ");
  204. strvbr=strvbru.Replace("s"," ");
  205. }
  206. if(i==29)
  207. {
  208. string[] strsp= str2.Split(' ');
  209. foreach(string strf in strsp)
  210. {
  211. string weba=strf;
  212. if(weba!="")
  213. webl=Double.Parse(weba);
  214. if(webl>0)
  215. break;
  216. }
  217. if(i==30)
  218. {
  219. string[] strsp= str2.Split(' ');
  220. foreach(string strf in strsp)
  221. {
  222. string weba=strf;
  223. if(weba!="")
  224. webh=Double.Parse(weba);
  225. if(webh>0&&webh!=webl)
  226. break;
  227. }
  228. }
  229. if(i==31)
  230. {
  231. string[] strsp= str2.Split(' ');
  232. foreach(string strf in strsp)
  233. {
  234. string weba=strf;
  235. if(weba!="")
  236. webh1=Double.Parse(weba);
  237. if(webh1>0&&webh1!=webl)
  238. break;
  239. }
  240. }
  241. if(i==32)
  242. {
  243. strve=str2;
  244. str2.Replace("w","");
  245. string[] strsp= str2.Split(' ');
  246. foreach(string strf in strsp)
  247. {
  248. string weba=strf;
  249. if(weba!="")
  250. webf=Double.Parse(weba);
  251. if(webf>0&&webf!=webl)
  252. break;
  253. }
  254. }
  255. if(i==33)
  256. {
  257. strve=str2;
  258. str2.Replace("w","");
  259. string[] strsp= str2.Split(' ');
  260. foreach(string strf in strsp)
  261. {
  262. string weba=strf;
  263. if(weba!="")
  264. webe=Double.Parse(weba);
  265. if(webe>0&&webe!=webl)
  266. break;
  267. }
  268. }
  269. if(i==34)
  270. {
  271. strve=str2;
  272. str2.Replace("w","");
  273. string[] strsp= str2.Split(' ');
  274. foreach(string strf in strsp)
  275. {
  276. string weba=strf;
  277. if(weba!="")
  278. webbo=Double.Parse(weba);
  279. if(webbo>0&&webbo!=webl)
  280. break;
  281. }
  282. }
  283. //
  284. if(i==35)
  285. {
  286. strve1=str2;
  287. }
  288. if(i==36)
  289. {
  290. if(strvbr.CompareTo(strve)==0)
  291. {
  292. //MessageBox.Show("Contour is closed");
  293. }
  294. else if(strvbr.CompareTo(strve1)==0)
  295. {
  296. }else
  297. {
  298. MessageBox.Show("Contour is not closed");
  299. }
  300. }
  301. if(i==52)
  302. {
  303. string strv=str2.Replace("v","");
  304. string stro=strv.Replace("o","");
  305. stro.Trim();
  306. string[] strf= stro.Split(' ');
  307. /*for(int bi=0;bi<=stro.Length;bi++)
  308. {
  309. if(strf[bi]!="")
  310. {
  311. bolt1= Double.Parse(strf[bi]);
  312. bi=bi+strf[bi].Length-1;
  313. if(bolt1>0&&strf[bi]!=" ")
  314. {
  315. bolt2=Double.Parse(strf[bi]);
  316. }
  317. if(bolt2>0)
  318. {
  319. bolt3=Double.Parse(strf[bi]);
  320. }
  321. }*/
  322. bolt11=Double.Parse(strf[6]);
  323. bolt12=Double.Parse(strf[11]);
  324. bolt13=Double.Parse(strf[17]);
  325. }
  326. if(i==53)
  327. {
  328. string strbov=str2.Replace("v","");
  329. string strboo=strbov.Replace("o","");
  330. string[] strbo2=strboo.Split(' ');
  331. bolt21=Double.Parse(strbo2[6]);
  332. bolt22=Double.Parse(strbo2[10]);
  333. bolt23=Double.Parse(strbo2[16]);
  334. }
  335. if(i==54)
  336. {
  337. string strbov3=str2.Replace("v","");
  338. string strboo3=strbov3.Replace("o","");
  339. string[] strbo3=strboo3.Split(' ');
  340. bolt31=Double.Parse(strbo3[6]);
  341. bolt32=Double.Parse(strbo3[11]);
  342. bolt33=Double.Parse(strbo3[17]);
  343. }
  344. if(i==55)
  345. {
  346. string strbov4=str2.Replace("v","");
  347. string strboo4=strbov4.Replace("o","");
  348. string[] strbo4=strboo4.Split(' ');
  349. bolt41=Double.Parse(strbo4[6]);
  350. bolt42=Double.Parse(strbo4[10]);
  351. bolt43=Double.Parse(strbo4[16]);
  352. }
  353. /* if(str2.StartsWith(" o")&&i>28)
  354. {
  355. strobr=str2.Replace("o"," ");
  356. string[] stro= strobr.Split(' ');
  357. if(i==linenum+4&&linenum!=0)
  358. {
  359. stroe=str2;
  360. }
  361. if(strobr==stroe)
  362. {
  363. }
  364. else
  365. {
  366. MessageBox.Show("Contour is not closed");
  367. }*/
  368. if(profile=="B")
  369. {
  370. plate();
  371. Bitmap img=new Bitmap("B-Sec.jpg");
  372. pictureBox1.Image=img;
  373. }
  374. if(profile=="I")
  375. {
  376. label8.Text=a.ToString();
  377. label10.Text=w.ToString();
  378. label12.Text=w.ToString();
  379. Double sum=b+c;
  380. label11.Text=sum.ToString();
  381. Image imgi=Image.FromFile("I-Sec.jpg");
  382. pictureBox1.Image=imgi;
  383. }
  384. PaintEventArgs el=null;
  385. OnPaint(el);
  386. }
  387. sr.Close();
  388. }
  389. catch(Exception ex)
  390. {
  391. //MessageBox.Show(ex.Message);
  392. Console.WriteLine(ex.Message);
  393. }
  394. finally
  395. {
  396. if (sr != null)
  397. sr.Close();
  398. if (sw != null)
  399. sw.Close();
  400. }
  401. }
  402.  
  403. protected override void OnPaint(PaintEventArgs e)
  404. {
  405. base.OnPaint(e);
  406. Graphics g=this.CreateGraphics();
  407. Pen myPen = new Pen(Color.Red,5);
  408. g.Clear(Form1.ActiveForm.BackColor);
  409. /* if(Form1.ActiveForm.Width<350+a)
  410. {
  411. //MessageBox.Show(d.ToString());
  412. a=a/10;
  413. }*/
  414. Graphics ge=this.CreateGraphics();
  415. //ge.DrawRectangle(p,300,150,300,150);
  416. SolidBrush Brush = new SolidBrush(Color.White);
  417. // int x=Form1.ActiveForm.Width;
  418. // int y=Form1.ActiveForm.Height;
  419. ge.FillRectangle(Brush,150,150,750,950);
  420. if(b>300)
  421. b=b/2;
  422. SolidBrush brush1=new SolidBrush(Color.Black);
  423. g.DrawRectangle(myPen,200,415-(int)c,(float)a*650/(float)a,150+2*(int)c);
  424. //g
  425. g.FillEllipse(brush1,(float)a*195/(float)a,560+(int)c,10,10);
  426. Graphics l=this.CreateGraphics();
  427. Pen myPen1 = new Pen(Color.Blue,5);
  428. l.DrawRectangle(myPen1,200,415,(float)a*650/(float)a,150);
  429. Graphics gi=this.CreateGraphics();
  430. Pen iPen=new Pen(Color.Blue,5);
  431. gi.DrawRectangle(iPen,200,230,(float)a*650/(float)a,150);
  432. gi.FillEllipse(brush1,195,(float)a*375/(float)a,10,10);
  433. Graphics g3=this.CreateGraphics();
  434. Pen myPen2=new Pen(Color.Blue,5);
  435. g3.DrawRectangle(myPen2,200,600,(float)a*650/(float)a,150);
  436. g3.FillEllipse(brush1,195,(float)a*745/(float)a,10,10);
  437. label13.Text="";
  438. label14.Text="";
  439. Graphics gweb=this.CreateGraphics();
  440. Pen p=new Pen(Color.Green,5);
  441. if(webe>0)
  442. {
  443. gweb.DrawLine(p,220,770,800-((float)webl-(float)webh1),770);
  444. gweb.DrawLine(p,220,770,220,770+((float)webbo*200/(float)webl));
  445. gweb.DrawLine(p,220,770+((float)webbo*200/(float)webl),800,770+((float)webbo*200/(float)webl));
  446. gweb.DrawLine(p,800,770+((float)webbo*200/(float)webl),800,770+(float)webh/3);
  447. gweb.DrawLine(p,800,770+(float)webh/3,800-((float)webl-(float)webh1),770+(float)webh/3);
  448. gweb.DrawLine(p,800-((float)webl-(float)webh1),770+(float)webh/3,800-((float)webl-(float)webh1),770);
  449. /* if(bolt13!=bolt23)
  450. {
  451. gweb.FillEllipse(brushg,800-(float)dist1,770+(float)bolt12,((float)bolt13)/2,((float)bolt13)/2);
  452. gweb.FillEllipse(brushb,800-(float)dist2/*((float)webl-(float)webh1),770+(float)bolt22,((float)bolt23)/2,((float)bolt23)/2);
  453. }
  454. if(bolt23!=bolt33&&bolt13==bolt33)
  455. {
  456. gweb.FillEllipse(brushg,800-(float)dist3,770+(float)bolt32,((float)bolt33)/2,((float)bolt33)/2);
  457. }
  458. if(bolt13!=bolt33&&bolt23==bolt33)
  459. {
  460. gweb.FillEllipse(brushb,800-(float)dist3,770+(float)bolt32,((float)bolt33)/2,((float)bolt33)/2);
  461. }
  462. if(bolt43!=bolt33&&bolt43!=bolt23&&bolt43!=bolt13)
  463. {
  464. gweb.FillEllipse(brushr,800-(float)dist4,770+(float)bolt42,((float)bolt43)/2,((float)bolt43)/2);
  465. }
  466. if(bolt43==bolt33)
  467. {
  468. gweb.FillEllipse(brushr,800-(float)dist4,770+(float)bolt42,((float)bolt43)/2,((float)bolt43)/2);
  469. }*/
  470. }
  471. else
  472. {
  473. Graphics gwebl=this.CreateGraphics();
  474. Pen Penw=new Pen(Color.Blue,5);
  475. float length=(float)webh*200/(float)webl;
  476. gwebl.DrawLine(Penw,200,770,(float)a*850/(float)a,770);
  477. gwebl.DrawLine(Penw,200,770,200,770+length);
  478. float length2=(float)webh1*200/(float)webl;
  479. gwebl.DrawLine(Penw,200,770+length,(float)a*850/(float)a,770+length);
  480. gwebl.DrawLine(Penw,(float)a*850/(float)a,770+length,(float)a*850/(float)a,770);
  481. }
  482. SolidBrush brushb=new SolidBrush(Color.Black);
  483. double dist1=webl-webh1;
  484. double dist2=webl-webh1;
  485. double dist3=(bolt31-bolt21);
  486. double dist4=(bolt41-bolt21);
  487. if(bolt13==bolt23&&bolt33==bolt43&&bolt13==bolt43&&bolt13==bolt33&&bolt23==bolt33&&bolt23==bolt43)
  488. {
  489. gweb.FillEllipse(brushb,800-(float)dist1,770+(float)bolt12,((float)bolt13)/2,((float)bolt13)/2);
  490. gweb.FillEllipse(brushb,800-(float)dist2/*((float)webl-(float)webh1)*/,770+(float)bolt22,((float)bolt23)/2,((float)bolt23)/2);
  491. gweb.FillEllipse(brushb,800-(float)dist3,770+(float)bolt32,((float)bolt33)/2,((float)bolt33)/2);
  492. gweb.FillEllipse(brushb,800-(float)dist4,770+(float)bolt42,((float)bolt43)/2,((float)bolt43)/2);
  493. }
  494. else
  495. {
  496. SolidBrush brushg=new SolidBrush(Color.Green);
  497. SolidBrush brushr=new SolidBrush(Color.Red);
  498. SolidBrush brushbl=new SolidBrush(Color.Blue);
  499. gweb.FillEllipse(brushb,800-(float)dist1,770+(float)bolt12,((float)bolt13)/2,((float)bolt13)/2);
  500. gweb.FillEllipse(brushg,800-(float)dist2/*((float)webl-(float)webh1)*/,770+(float)bolt22,((float)bolt23)/2,((float)bolt23)/2);
  501. gweb.FillEllipse(brushr,800-(float)dist3,770+(float)bolt32,((float)bolt33)/2,((float)bolt33)/2);
  502. gweb.FillEllipse(brushbl,800-(float)dist4,770+(float)bolt42,((float)bolt43)/2,((float)bolt43)/2);
  503. }
  504. }
Jan 5 '09 #1
Share this Question
Share on Google+
2 Replies


Curtis Rutland
Expert 2.5K+
P: 3,256
I can promise you that nobody is going to read 500 lines of unformatted code to help fix a problem that you haven't explained very well.

Clarify your problem, and chop down the code sample to include only the important stuff. And remember to use [code] tags when you post it.

MODERATOR
Jan 5 '09 #2

Plater
Expert 5K+
P: 7,872
Since you have overwritten the onpaint method. You can control when it gets drawn and when it does its own drawing (base.onpaint())
Use a boolean to allow/dissallow the code from executing if you must.
Jan 5 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.