错误:并非所有代码路径都返回值 [英] Error: not all code paths return value

查看:94
本文介绍了错误:并非所有代码路径都返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我试图创建它实际上用vb6编写的缩略图,我将其转换为c#并尝试创建缩略图,当我进行显式转换时它就像上面提到的错误一样。



请有人帮忙。



我尝试过:



hi I tried to create thumbnail its actually written in vb6 , I converted it into c# and trying to create thumbnail , when I do explicit conversion it says like above mentioned error.

please someone help.

What I have tried:

private bool AddThumbnail()
       {

           savdImgCnt = 0;

           Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);

           Panel panel1 = new Panel();
           var _with1 = panel1;
           _with1.Visible = true;
           _with1.Location = new Point(61, 130);
           _with1.Name = "panel1";
           _with1.Size = new Size(650, 600);
           _with1.AutoScroll = true;
           _with1.BorderStyle = BorderStyle.Fixed3D;
           this.Controls.Add(panel1);

           int btnposition_X = 0;
           int btnposition_Y = 0;

           btnposition_X = 15;
           btnposition_Y = 10;

           string strFileSize = "";


           Myconnection obj = new Myconnection();

           obj.SetConnection();
           OleDbCommand cmd = default(OleDbCommand);
           OleDbDataReader dr = default(OleDbDataReader);

           cmd = new OleDbCommand("Select * from PresetDetails", obj.con);
           dr = cmd.ExecuteReader();

           if (dr.HasRows == true)
           {
              while (dr.Read())
               {
                   if (File.Exists("\\saved files\\" + dr[1] + ".bmp"))
                   {
                       btn[savdImgCnt] = new Button();
                       var _with2 = btn[savdImgCnt];
                       _with2.Height = 110;
                       _with2.Width = 110;
                       _with2.Visible = true;
                       _with2.Name = dr[1].ToString();
                       _with2.Location = new System.Drawing.Point(btnposition_X, btnposition_Y);
                       _with2.ForeColor = Color.Chocolate;


                       btn[savdImgCnt].Click += Dynamic_Method;




                       bitmap = new Bitmap("\\saved files\\" + dr[1] + ".bmp");


                       thmbitmap= bitmap.GetThumbnailImage(100, 100, myCallback, IntPtr.Zero);





                       bitmap.Dispose();

                       //'thmbitmap.Save(My.Application.Info.DirectoryPath & "\Thumb files\" & dr(0).ToString & ".bmp")
                       btn[savdImgCnt].Image = thmbitmap;


                       //'btn[savdImgCnt].TabIndex = 0;
                       //Controls.Add(btn[savdImgCnt]);


                       label1[0] = new Label();
                       var _with3 = label1[0];
                       _with3.AutoSize = true;
                       _with3.Text = dr[1].ToString();
                       _with3.Location = new System.Drawing.Point(btnposition_X + 35, btnposition_Y + 110);

                       //'Me.Controls.Add(label1(0))
                       panel1.Controls.Add(label1[0]);

                       label1[1] = new Label();
                       var _with4 = label1[1];
                       _with4.AutoSize = true;
                       _with4.Text = dr[2].ToString();
                       _with4.Location = new System.Drawing.Point(btnposition_X + 1, btnposition_Y + 130);

                       //'Me.Controls.Add(label1(1))
                       panel1.Controls.Add(btn[savdImgCnt]);
                       panel1.Controls.Add(label1[1]);

                       savdImgCnt = savdImgCnt + 1;
                       btnposition_X = btnposition_X + 150;
                       if (savdImgCnt % 4 == 0)
                       {
                           btnposition_X = 15;
                           btnposition_Y = btnposition_Y + 150;
                       }

                   }

               }
           }

           obj.CloseConnection();

推荐答案

您将方法声明为 bool 但是你没有任何返回语句。

除非您的代码中的每条路线都意味着返回系统将(正确地)抱怨,因为它无法保证将任何值传递给调用者。



将方法更改为 void 输入:

You declare the method as a bool but you don't have any return statement.
Unless every route through your code means a return the system will (correctly) complain because it cannot guarantee to pass any value back to the caller.

Either change your method to a void type:
private void AddThumbnail()

或添加返回最后的陈述。


这篇关于错误:并非所有代码路径都返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆