I'm trying to create a music player with an audio visualizer starting from a windows game project on VS 2019. To do so I created a custom display, draggable from the toolbox, in order to put it inside a form.
From tutorials I've seen it is necessary to include three classes from GraphicsDevice and I've done it, but when I put them inside the code, the Display class does not inherit and VS does not recognize the keywords.
To be precise WinFormsGraphicsDevice is marked as an error, and its methods as well.
Does anybody have any hints about this?
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WindowsGame2.CustomControls
{
public class Display : WinFormsGraphicsDevice.GraphicsDeviceControl
{
protected override void Initialize()
{
}
protected override void Draw()
{
GraphicsDevice.Clear();
}
}
}
Related
I've recently tried to customize the tabbar using a custom ShellRenderer in my app using Xamarin and Visual Studio 2019. I've found this question where someone does exactly what I need and the question has an answer which explains it in great detail.
Now, my problem is that when trying to build the app, I get the following error:
'CustomBottomNavAppearance' does not implement interface member 'IShellBottomNavViewAppearanceTracker.SetAppearance(BottomNavigationView,IShellAppearanceElement)' (Errorcode CS0535, line 32)
Now, the sample project that the user in the other question provides works perfectly on my machine, yet implementing it in my project doesn't work, although they are practiacally identical.
I expect this to be very obvious for an advanced user, so sorry about that, I'm still learning and would like to just implement this feature right now, even if my skills might not allow me to do that.
Thanks in advance for any replies!
This is my 'MyShellRenderer.cs' class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Google.Android.Material.BottomNavigation;
using MyProject;
using MyProject.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(AppShell), typeof(MyShellRenderer))]
namespace MyProject.Droid
{
public class MyShellRenderer : ShellRenderer
{
public MyShellRenderer(Context context) : base(context)
{
}
protected override IShellBottomNavViewAppearanceTracker CreateBottomNavViewAppearanceTracker(ShellItem shellItem)
{
return new CustomBottomNavAppearance();
}
}
public class CustomBottomNavAppearance : IShellBottomNavViewAppearanceTracker
{
public void Dispose()
{
}
public void ResetAppearance(BottomNavigationView bottomView)
{
}
public void SetAppearance(BottomNavigationView bottomView, ShellAppearance appearance)
{
IMenu myMenu = bottomView.Menu;
IMenuItem myItemOne = myMenu.GetItem(0);
if (myItemOne.IsChecked)
{
myItemOne.SetIcon(Resource.Drawable.icon_about);
}
else
{
myItemOne.SetIcon(Resource.Drawable.icon_feed);
}
}
}
}
Edit: I've just found out that the issue actually only exists with the Android version (well, the iOS version at least doesn't throw the error).
Update: I have been able to fix the issue by using "using Google.Android.Material.BottomNavigation;" "using Android.Support.Design.Widget;". My guess it that the old one is now deprecated and only works with the 4.x.x releases, not my 5.x.x release. Thanks everyone!
Per this docs,The error does not implement interface member Errorcode CS0535 means A class must implement all members of interfaces from which it derives or else be declared abstract.So the issue must be that the method SetAppearance has not been correctly implemented.When I Remove or Comment the SetAppearance method, the error appears.
The solution is that using using Google.Android.Material.BottomNavigation instead of using Android.Support.Design.Widget.
Im making an Android App using Xamarin.Android in Visual Studio and I've been trying to disable the back button in my secondary activity, and the methods I've been using is adding this code into the activity
#Override
public void onBackPressed() {
}
So the code would look like this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Java.Lang;
namespace The_Coder_Quiz
{
[Activity(Label = "Activity2")]
public class Activity2 : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.easyQuiz);
// Create your application here
}
#Override
public void onBackPressed()
{
//Include the code here
return;
}
}
}
But that gave me an error which was:
member modifier 'public' must precede the member type and name
Im assuming that is because im doing the project in C#, what would be the correct solution since im doing this in C# and not Java (new to android development)
Im trying to keep off StackOverflow when learning but its kinda hard to find references online for Android Development in C#
The correct way to do an override in C# is:
public override void OnBackPressed()
{
//Include the code here
return;
}
For example if it is a login page (Activity):
public override void OnBackPressed(){
//by this way.. user want be able to hit the back button
// unless user is logged in
if (user.IsLoggedIn()){
base.OnBackPressed();
}
}
Check this:
OnBackPressed in Xamarin Android
And about android development using Xamarin, these are some tutorials:
Xamarin.Android Get Started
JoeRock on Youtube
Very basic knowledge on c# and is the first i use anything p/invoke related.
Help me pls, i have made this code but it doesnt seem to work.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
[DllImport("C:\\Users\\lchris\\Desktop\\SevenZipLib_9.13.2\\SevenZipLib\\SevenZipLib\\7z86.dll")]
public static extern void SevenZipArchive(string c);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
using (SevenZipArchive archive = new SevenZipArchive("file.rar"))
{
foreach (ArchiveEntry entry in archive)
{
Console.WriteLine(entry.FileName);
}
}
}
}
}
It tells me that SevenZipArchive is a 'Method' and is being used like a 'type'.
I have include the library to my project already, i just dont know how to use it.
Here is the library:
https://sevenziplib.codeplex.com/
You first need to remove this code:
[DllImport("...")]
public static extern void SevenZipArchive(string c);
You do not need to provide any p/invoke declarations. The library wraps that up for you.
This is a .net assembly. You use it just as you use any other. Take the following steps:
Download the project. You already did that I think.
Build the solution. Make sure that
In your project, add a reference to the assembly that you built in the previous stage. It's SevenZipLib\bin\Debug\SevenZipLib.dll or SevenZipLib\bin\Release\SevenZipLib.dll depending on the target you selected.
Add using SevenZipLib; to your project code to to gain access to the namespace.
Once you've done that your code will work. You can use the tests project that is supplied as part of the download as a rich source of example code.
I need to override the draw method, but I get the error message:
Draw(System.Drawing.PointF)' is marked as an override but no suitable method found to override (CS0115).
This is what I do: I create a new project, add an empty class and try to override.
Here's the code:
using System;
using UIKit;
using System.Drawing;
using CoreGraphics;
using CoreImage;
using Foundation;
using CoreAnimation;
namespace Test
{
public class Tester : UIView
{
CGPath path;
public override void Draw (PointF rect){
base.Draw ();
}
public Tester ()
{
path = new CGPath ();
}
}
}
Actually I'm trying the Xamarin's tutorial.
http://developer.xamarin.com/guides/ios/application_fundamentals/graphics_animation_walkthrough/
The problem is that you create a program with the Unified API (see "using CoreImage" at the top). In Unified API, we no longer use PointF, SizeF or RectangleF, as those are 32-bit structures, so they do not work on 32/64 bit modes.
In Unified, you need to use "CGRect" instead of "RectangleF"
So to fix your program, all you have to do is replace "RectangleF" with "CGRect"
The tutorials currently reflect the Classic API, and once we officially release the final version of Unified, they will be switched over.
You can't override different methods. The original method has no arguments. If you want to override the Draw method, you need to delete your Draw function arguments.
I added to the reference the OpenHardwareMonitorLib.dll
Now I added in my code: using OpenHardwareMonitor.Hardware;.
Then I did in the top form level: Isensor Sensor;
But I can't "new" it i cant create an instance of it and I'm getting null exception on it in the constructor:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using OpenHardwareMonitor.Hardware;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
ISensor Sensor;
public Form1()
{
InitializeComponent();
string t = Sensor.Name;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}
Cannot create an instance of the abstract class or interface 'OpenHardwareMonitor.Hardware
I tried ot look in the source code in the code.google.com site: http://code.google.com/p/open-hardware-monitor/source/browse/#svn%2Ftags%2F0.3.2%2FWMI
But i dont want to use all this code. I downloaded the program Open Hardware Monitor and except the exe file there is a dll file im using now in my project i was sure i can use the dll to use it easier. All i want for now is to get the temperature of the video card gpu.
First, you can't new interfaces. You can only new concrete classes.
Second, I recommend renaming your variable from Sensor to sensor, or _sensor, or something along these lines. There is a Sensor class. It's best to avoid confusion.
What I did was downloaded the DLL and opened it up in ILSpy. Let's see what classes implement this interface. I urge you to download ILSpy and try this out for yourself.
Here's the resulting ILSpy window. Now in the bottom right I had done an "Analyze" on the interface to see where it is exposed. There don't appear to be any factory methods that return an ISensor.
Back over on the left side, we see that one class implements ISensor: the Sensor class. This class has four constructors. These will come up in intellisense in Visual Studio, or if you navigate to the Sensor class in ILSpy you can see the constructors.
What you'll end up needing to do is sensor = new Sensor(...); As for which constructor you use... that's up to you.